Analysis API: add test for KtDeclaration.getReturnKtType

FE1.0 always return kotlin.Unit as return type for constructors while
FIR returns the constructed class type. I am not sure which is more
desirable. Also, I am not sure how to make FE1.0 behave the same way.
This commit is contained in:
Tianyu Geng
2021-11-18 14:05:29 -08:00
committed by Ilya Kirillov
parent 0e93931e24
commit f1d0791f15
28 changed files with 402 additions and 2 deletions
@@ -0,0 +1,4 @@
Foo@(1,1)
Foo@(1,13) : kotlin.Unit
t@(1,14) : T
i@(1,24) : kotlin.Int
@@ -0,0 +1 @@
class Foo<T>(val t: T, val i: Int)
@@ -0,0 +1,4 @@
Foo@(1,1)
Foo@(1,13) : Foo<T>
t@(1,14) : T
i@(1,24) : kotlin.Int
@@ -0,0 +1,10 @@
lazy@(3,1) : Lazy<T>
initializer@(3,14) : () -> T
Lazy@(5,1)
Lazy@(5,14) : kotlin.Unit
value@(5,15) : T
getValue@(7,1) : T
thisRef@(7,42) : kotlin.Any?
property@(7,57) : kotlin.reflect.KProperty<*>
A@(9,1)
i@(10,5) : kotlin.Int
@@ -0,0 +1,13 @@
import kotlin.reflect.KProperty
fun <T> lazy(initializer: () -> T): Lazy<T> = Lazy(initializer())
class Lazy<T>(val value: T)
inline operator fun <T> Lazy<T>.getValue(thisRef: Any?, property: KProperty<*>): T = value
class A {
val i by lazy {
1
}
}
@@ -0,0 +1,10 @@
lazy@(3,1) : Lazy<T>
initializer@(3,14) : () -> T
Lazy@(5,1)
Lazy@(5,14) : Lazy<T>
value@(5,15) : T
getValue@(7,1) : T
thisRef@(7,42) : kotlin.Any?
property@(7,57) : kotlin.reflect.KProperty<*>
A@(9,1)
i@(10,5) : kotlin.Int
@@ -0,0 +1,4 @@
val f1: () -> Unit = {}
val f2 = {}
val f3: String.() -> String = { this }
fun <T> f4(): Int.(T) -> String = { "" }
@@ -0,0 +1,5 @@
f1@(1,1) : () -> kotlin.Unit
f2@(2,1) : () -> kotlin.Unit
f3@(3,1) : kotlin.String.() -> kotlin.String
f4@(4,1) : kotlin.Int.(T) -> kotlin.String
KtParameter@(4,20) : T
@@ -0,0 +1,20 @@
fun test1() {
val i = 1
fun foo() = ""
val f1 = {}
val f2: String.(Int) -> String = { this + it }
}
fun <T> test2(t1: T) {
val t2 = t1
fun foo() = t1
val f = { t1 }
}
fun test3(
val i: Int = run {
val j = 1
j
}
) {
}
@@ -0,0 +1,14 @@
test1@(1,1) : kotlin.Unit
i@(2,5) : kotlin.Int
foo@(3,5) : kotlin.String
f1@(4,5) : () -> kotlin.Unit
f2@(5,5) : kotlin.String.(kotlin.Int) -> kotlin.String
KtParameter@(5,21) : kotlin.Int
test2@(8,1) : kotlin.Unit
t1@(8,15) : T
t2@(9,5) : T
foo@(10,5) : T
f@(11,5) : () -> T
test3@(14,1) : kotlin.Unit
i@(15,5) : kotlin.Int
j@(16,9) : kotlin.Int
@@ -0,0 +1,17 @@
interface A
class B: A
abstract class Super {
abstract val a: A
abstract val b: B
abstract fun getA(): A
abstract fun getB(): B
}
class Sub: {
override val a = B()
override val b = B()
override fun getA() = B()
override fun getB() = B()
}
@@ -0,0 +1,12 @@
A@(1,1)
B@(3,1)
Super@(5,1)
a@(6,5) : A
b@(7,5) : B
getA@(8,5) : A
getB@(9,5) : B
Sub@(12,1)
a@(13,5) : B
b@(14,5) : B
getA@(15,5) : B
getB@(16,5) : B
@@ -0,0 +1,9 @@
i@(1,1) : kotlin.Int
KtPropertyAccessor@(2,5) : kotlin.Int
KtPropertyAccessor@(3,5) : kotlin.Unit
value@(3,9) : kotlin.Unit
A@(5,1)
j@(6,5) : kotlin.Int
KtPropertyAccessor@(7,9) : kotlin.Int
KtPropertyAccessor@(8,9) : kotlin.Unit
value@(8,13) : kotlin.Unit
@@ -0,0 +1,9 @@
var i: Int
get() = 1
set(value) {}
class A {
val j: Int
get() = 2
set(value) {}
}
@@ -0,0 +1,9 @@
i@(1,1) : kotlin.Int
KtPropertyAccessor@(2,5) : kotlin.Int
KtPropertyAccessor@(3,5) : kotlin.Unit
value@(3,9) : kotlin.Int
A@(5,1)
j@(6,5) : kotlin.Int
KtPropertyAccessor@(7,9) : kotlin.Int
KtPropertyAccessor@(8,9) : kotlin.Unit
value@(8,13) : kotlin.Int
@@ -0,0 +1,8 @@
val i: Int
val j = 1
val s = ""
fun procedure() {}
fun procedure(i: Int) {}
fun returnIntOne() = 1
fun id(i: Int) = i
fun throwException() = throw Exception()
@@ -0,0 +1,10 @@
i@(1,1) : kotlin.Int
j@(2,1) : kotlin.Int
s@(3,1) : kotlin.String
procedure@(4,1) : kotlin.Unit
procedure@(5,1) : kotlin.Unit
i@(5,15) : kotlin.Int
returnIntOne@(6,1) : kotlin.Int
id@(7,1) : kotlin.Int
i@(7,8) : kotlin.Int
throwException@(8,1) : kotlin.Nothing
@@ -0,0 +1,8 @@
fun <T> id(t: T) = t
fun <C : Collection<*>> C.mySize = size
fun <T> foo(): Foo<T> = Foo()
class Foo<T> {
val t: T
fun getT(): T
fun <R> getR(): R
}
@@ -0,0 +1,8 @@
id@(1,1) : T
t@(1,12) : T
mySize@(2,1) : kotlin.Int
foo@(3,1) : Foo<T>
Foo@(4,1)
t@(5,5) : T
getT@(6,5) : T
getR@(7,5) : R