[FIR-TEST] Move analysis tests to separate module

This commit is contained in:
Dmitriy Novozhilov
2020-03-18 15:10:46 +03:00
parent 3a479d5d16
commit cc07ae96b3
1477 changed files with 1001 additions and 980 deletions
@@ -0,0 +1,13 @@
interface KaptLogger {
val isVerbose: Boolean
fun warn(message: String)
fun error(message: String)
}
fun test(logger: KaptLogger) {
val func = if (logger.isVerbose)
logger::warn
else
logger::error
}
@@ -0,0 +1,21 @@
FILE: callableReferenceOnInstance.kt
public abstract interface KaptLogger : R|kotlin/Any| {
public abstract val isVerbose: R|kotlin/Boolean|
public get(): R|kotlin/Boolean|
public abstract fun warn(message: R|kotlin/String|): R|kotlin/Unit|
public abstract fun error(message: R|kotlin/String|): R|kotlin/Unit|
}
public final fun test(logger: R|KaptLogger|): R|kotlin/Unit| {
lval func: R|kotlin/reflect/KFunction1<kotlin/String, kotlin/Unit>| = when () {
R|<local>/logger|.R|/KaptLogger.isVerbose| -> {
R|<local>/logger|::R|/KaptLogger.warn|
}
else -> {
R|<local>/logger|::R|/KaptLogger.error|
}
}
}
@@ -0,0 +1,7 @@
fun <T, R> List<T>.myMap(block: (T) -> R): List<R> = null!!
fun test_1() {
class Data(val x: Int)
val datas: List<Data> = null!!
val xs = datas.myMap(Data::x)
}
@@ -0,0 +1,18 @@
FILE: callableReferenceToLocalClass.kt
public final fun <T, R> R|kotlin/collections/List<T>|.myMap(block: R|(T) -> R|): R|kotlin/collections/List<R>| {
^myMap Null(null)!!
}
public final fun test_1(): R|kotlin/Unit| {
local final class Data : R|kotlin/Any| {
public constructor(x: R|kotlin/Int|): R|Data| {
super<R|kotlin/Any|>()
}
public final val x: R|kotlin/Int| = R|<local>/x|
public get(): R|kotlin/Int|
}
lval datas: R|kotlin/collections/List<Data>| = Null(null)!!
lval xs: R|kotlin/collections/List<kotlin/Int>| = R|<local>/datas|.R|/myMap|<R|Data|, R|kotlin/Int|>(Q|Data|::R|/Data.x|)
}
@@ -0,0 +1,9 @@
class A {
fun foo(s: String, flag: Boolean = true) {}
}
inline fun <T> T.myLet(block: (T) -> Unit) {}
fun test(a: A, s: String) {
s.myLet(a::foo)
}
@@ -0,0 +1,15 @@
FILE: callableReferencesAndDefaultParameters.kt
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public final fun foo(s: R|kotlin/String|, flag: R|kotlin/Boolean| = Boolean(true)): R|kotlin/Unit| {
}
}
public final inline fun <T> R|T|.myLet(block: R|(T) -> kotlin/Unit|): R|kotlin/Unit| {
}
public final fun test(a: R|A|, s: R|kotlin/String|): R|kotlin/Unit| {
R|<local>/s|.R|/myLet|<R|kotlin/String|>(R|<local>/a|::R|/A.foo|)
}
@@ -0,0 +1,11 @@
// FILE: B.java
public class B<E extends A> {}
// FILE: main.kt
interface A {}
fun <D : A> foo(b: B<D>) {}
fun main(b: B<*>) {
foo(b)
}
@@ -0,0 +1,8 @@
FILE: main.kt
public abstract interface A : R|kotlin/Any| {
}
public final fun <D : R|A|> foo(b: R|B<D>|): R|kotlin/Unit| {
}
public final fun main(b: R|B<*>|): R|kotlin/Unit| {
R|/foo|<R|CapturedType(*)|>(R|<local>/b|)
}
@@ -0,0 +1,7 @@
fun <X> test_1(a: X) {
if (a is String?) {
takeString(a!!)
}
}
fun takeString(s: String) {}
@@ -0,0 +1,11 @@
FILE: definitelyNotNullIntersectionType.kt
public final fun <X> test_1(a: R|X|): R|kotlin/Unit| {
when () {
(R|<local>/a| is R|kotlin/String?|) -> {
R|/takeString|(R|<local>/a|!!)
}
}
}
public final fun takeString(s: R|kotlin/String|): R|kotlin/Unit| {
}
@@ -0,0 +1,16 @@
class A
class B {
val memberVal: A = A()
fun memberFun(): A = A()
}
val B.extensionVal: A
get() = A()
fun B.extensionFun(): A = A()
fun test_1() {
val extensionValRef = B::extensionVal
val extensionFunRef = B::extensionFun
}
@@ -0,0 +1,31 @@
FILE: extensionCallableReferences.kt
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public final class B : R|kotlin/Any| {
public constructor(): R|B| {
super<R|kotlin/Any|>()
}
public final val memberVal: R|A| = R|/A.A|()
public get(): R|A|
public final fun memberFun(): R|A| {
^memberFun R|/A.A|()
}
}
public final val R|B|.extensionVal: R|A|
public get(): R|A| {
^ R|/A.A|()
}
public final fun R|B|.extensionFun(): R|A| {
^extensionFun R|/A.A|()
}
public final fun test_1(): R|kotlin/Unit| {
lval extensionValRef: R|kotlin/reflect/KProperty1<B, A>| = Q|B|::R|/extensionVal|
lval extensionFunRef: R|kotlin/reflect/KFunction1<B, A>| = Q|B|::R|/extensionFun|
}
@@ -0,0 +1,15 @@
// ISSUE: KT-37070
class A
fun test(a: A) {
val lambda = a.let {
{ it }
}
val alsoA = lambda()
takeA(alsoA)
}
fun takeA(a: A) {}
@@ -0,0 +1,20 @@
FILE: lambdaAsReturnStatementOfLambda.kt
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public final fun test(a: R|A|): R|kotlin/Unit| {
lval lambda: R|() -> A| = R|<local>/a|.R|kotlin/let|<R|A|, R|() -> A|>(<L> = let@fun <anonymous>(it: R|A|): R|() -> A| <kind=EXACTLY_ONCE> {
^ let@fun <anonymous>(): R|A| {
^ R|<local>/it|
}
}
)
lval alsoA: R|A| = R|<local>/lambda|.R|FakeOverride<kotlin/Function0.invoke: R|A|>|()
R|/takeA|(R|<local>/alsoA|)
}
public final fun takeA(a: R|A|): R|kotlin/Unit| {
}
@@ -0,0 +1,21 @@
fun <T> myRun(computable: () -> T): T = TODO()
interface Inv<W>
interface MyMap<K, V> {
val k: K
val v: V
}
val w: Inv<String> = TODO()
public fun <X, K> Inv<X>.associateBy1(keySelector: (X) -> K): MyMap<K, X> = TODO()
val x = myRun {
w.associateBy1 { f -> f.length }
}
fun foo(m: MyMap<Int, String>) {}
fun main() {
foo(x)
}
@@ -0,0 +1,32 @@
FILE: nestedLambdas.kt
public final fun <T> myRun(computable: R|() -> T|): R|T| {
^myRun R|kotlin/TODO|()
}
public abstract interface Inv<W> : R|kotlin/Any| {
}
public abstract interface MyMap<K, V> : R|kotlin/Any| {
public abstract val k: R|K|
public get(): R|K|
public abstract val v: R|V|
public get(): R|V|
}
public final val w: R|Inv<kotlin/String>| = R|kotlin/TODO|()
public get(): R|Inv<kotlin/String>|
public final fun <X, K> R|Inv<X>|.associateBy1(keySelector: R|(X) -> K|): R|MyMap<K, X>| {
^associateBy1 R|kotlin/TODO|()
}
public final val x: R|MyMap<kotlin/Int, kotlin/String>| = R|/myRun|<R|MyMap<kotlin/Int, kotlin/String>|>(<L> = myRun@fun <anonymous>(): R|MyMap<kotlin/Int, kotlin/String>| {
^ R|/w|.R|/associateBy1|<R|kotlin/String|, R|kotlin/Int|>(<L> = associateBy1@fun <anonymous>(f: R|kotlin/String|): R|kotlin/Int| {
^ R|<local>/f|.R|kotlin/String.length|
}
)
}
)
public get(): R|MyMap<kotlin/Int, kotlin/String>|
public final fun foo(m: R|MyMap<kotlin/Int, kotlin/String>|): R|kotlin/Unit| {
}
public final fun main(): R|kotlin/Unit| {
R|/foo|(R|/x|)
}
@@ -0,0 +1,36 @@
interface ResolvedCall<D : CallableDescriptor> {
var d: D
}
interface CallableDescriptor
fun <D : CallableDescriptor> ResolvedCall<D>.getParameterForArgument(): String = ""
fun <D : CallableDescriptor> ResolvedCall<D>.updateD(d: D): D {
this.d = d
return d
}
fun test_1_1(resolvedCall: ResolvedCall<out CallableDescriptor>) {
resolvedCall.getParameterForArgument() // should be ok
}
fun test_1_2(resolvedCall: ResolvedCall<in CallableDescriptor>) {
resolvedCall.getParameterForArgument() // should be ok
}
fun test_1_3(resolvedCall: ResolvedCall<CallableDescriptor>) {
resolvedCall.getParameterForArgument() // should be ok
}
fun test_2_1(resolvedCall: ResolvedCall<out CallableDescriptor>, d: CallableDescriptor) {
val x = resolvedCall.<!INAPPLICABLE_CANDIDATE!>updateD<!>(d) // should fail
}
fun test_2_2(resolvedCall: ResolvedCall<in CallableDescriptor>, d: CallableDescriptor) {
val x = resolvedCall.updateD(d) // should be ok
}
fun test_2_3(resolvedCall: ResolvedCall<CallableDescriptor>, d: CallableDescriptor) {
val x = resolvedCall.updateD(d) // should be ok
}
@@ -0,0 +1,34 @@
FILE: receiverWithCapturedType.kt
public abstract interface ResolvedCall<D : R|CallableDescriptor|> : R|kotlin/Any| {
public abstract var d: R|D|
public get(): R|D|
public set(value: R|D|): R|kotlin/Unit|
}
public abstract interface CallableDescriptor : R|kotlin/Any| {
}
public final fun <D : R|CallableDescriptor|> R|ResolvedCall<D>|.getParameterForArgument(): R|kotlin/String| {
^getParameterForArgument String()
}
public final fun <D : R|CallableDescriptor|> R|ResolvedCall<D>|.updateD(d: R|D|): R|D| {
this@R|/updateD|.R|FakeOverride</ResolvedCall.d: R|D|>| = R|<local>/d|
^updateD R|<local>/d|
}
public final fun test_1_1(resolvedCall: R|ResolvedCall<out CallableDescriptor>|): R|kotlin/Unit| {
R|<local>/resolvedCall|.R|/getParameterForArgument|<R|CapturedType(out CallableDescriptor)|>()
}
public final fun test_1_2(resolvedCall: R|ResolvedCall<in CallableDescriptor>|): R|kotlin/Unit| {
R|<local>/resolvedCall|.R|/getParameterForArgument|<R|CapturedType(in CallableDescriptor)|>()
}
public final fun test_1_3(resolvedCall: R|ResolvedCall<CallableDescriptor>|): R|kotlin/Unit| {
R|<local>/resolvedCall|.R|/getParameterForArgument|<R|CallableDescriptor|>()
}
public final fun test_2_1(resolvedCall: R|ResolvedCall<out CallableDescriptor>|, d: R|CallableDescriptor|): R|kotlin/Unit| {
lval x: <ERROR TYPE REF: Inapplicable(INAPPLICABLE): [/updateD]> = R|<local>/resolvedCall|.<Inapplicable(INAPPLICABLE): [/updateD]>#(R|<local>/d|)
}
public final fun test_2_2(resolvedCall: R|ResolvedCall<in CallableDescriptor>|, d: R|CallableDescriptor|): R|kotlin/Unit| {
lval x: R|CallableDescriptor| = R|<local>/resolvedCall|.R|/updateD|<R|CapturedType(in CallableDescriptor)|>(R|<local>/d|)
}
public final fun test_2_3(resolvedCall: R|ResolvedCall<CallableDescriptor>|, d: R|CallableDescriptor|): R|kotlin/Unit| {
lval x: R|CallableDescriptor| = R|<local>/resolvedCall|.R|/updateD|<R|CallableDescriptor|>(R|<local>/d|)
}
@@ -0,0 +1,21 @@
interface Ann {
fun foo()
}
interface KC<T> {
val x: T
}
fun <T> id(x: KC<T>): KC<T> = x
fun <T> KC<T>.idR(): KC<T> = this
val <T> KC<T>.idP: KC<T> get() = this
private fun getSetterInfos(kc: KC<out Ann>) {
id(kc).x.foo()
kc.idR().x.foo()
kc.idP.x.foo()
val x1 = id(kc)
val x2 = kc.idR()
val x3 = kc.idP
}
@@ -0,0 +1,28 @@
FILE: simpleCapturedTypes.kt
public abstract interface Ann : R|kotlin/Any| {
public abstract fun foo(): R|kotlin/Unit|
}
public abstract interface KC<T> : R|kotlin/Any| {
public abstract val x: R|T|
public get(): R|T|
}
public final fun <T> id(x: R|KC<T>|): R|KC<T>| {
^id R|<local>/x|
}
public final fun <T> R|KC<T>|.idR(): R|KC<T>| {
^idR this@R|/idR|
}
public final val <T> R|KC<T>|.idP: R|KC<T>|
public get(): R|KC<T>| {
^ this@R|/idP|
}
private final fun getSetterInfos(kc: R|KC<out Ann>|): R|kotlin/Unit| {
R|/id|<R|CapturedType(out Ann)|>(R|<local>/kc|).R|FakeOverride</KC.x: R|Ann|>|.R|/Ann.foo|()
R|<local>/kc|.R|/idR|<R|CapturedType(out Ann)|>().R|FakeOverride</KC.x: R|Ann|>|.R|/Ann.foo|()
R|<local>/kc|.R|/idP|<R|CapturedType(out Ann)|>.R|FakeOverride</KC.x: R|Ann|>|.R|/Ann.foo|()
lval x1: R|KC<out Ann>| = R|/id|<R|CapturedType(out Ann)|>(R|<local>/kc|)
lval x2: R|KC<out Ann>| = R|<local>/kc|.R|/idR|<R|CapturedType(out Ann)|>()
lval x3: R|KC<out Ann>| = R|<local>/kc|.R|/idP|<R|CapturedType(out Ann)|>
}
@@ -0,0 +1,14 @@
typealias SymbolToTransformer = MutableMap<Int, (String) -> Double>
fun SymbolToTransformer.add() {}
fun foo(
symbolToTransformer: SymbolToTransformer
) {
symbolToTransformer.myApply {
add()
}
}
fun <T> T.myApply(x: T.() -> Unit) {}
@@ -0,0 +1,12 @@
FILE: typeDepthForTypeAlias.kt
public final typealias SymbolToTransformer = R|kotlin/collections/MutableMap<kotlin/Int, kotlin/Function1<kotlin/String, kotlin/Double>>|
public final fun R|SymbolToTransformer|.add(): R|kotlin/Unit| {
}
public final fun foo(symbolToTransformer: R|SymbolToTransformer|): R|kotlin/Unit| {
R|<local>/symbolToTransformer|.R|/myApply|<R|kotlin/collections/MutableMap<kotlin/Int, kotlin/Function1<kotlin/String, kotlin/Double>>|>(<L> = myApply@fun R|kotlin/collections/MutableMap<kotlin/Int, kotlin/Function1<kotlin/String, kotlin/Double>>|.<anonymous>(): R|kotlin/Unit| {
this@R|special/anonymous|.R|/add|()
}
)
}
public final fun <T> R|T|.myApply(x: R|T.() -> kotlin/Unit|): R|kotlin/Unit| {
}