JVM: partially reify typeOf and signatures as soon as possible
E.g. when substituting T -> Array<T>, write the bytecode for the Array<...> part for typeOf. This fixes various issues where either Array nesting levels, nullability information (for typeOf), or entire reification markers were missing, causing incorrect outputs ranging from missing `?`s to missing `[]`s to just reified types not really being reified. ^KT-53761 Fixed
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.typeOf
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <reified T> typeOfArrayOfNArrayOf() =
|
||||
typeOf<Array<Array<T>?>>()
|
||||
|
||||
inline fun <reified T> myTypeOf() =
|
||||
typeOf<T>()
|
||||
|
||||
inline fun <reified T> myTypeOfArrayOfNArrayOf() =
|
||||
typeOf<Array<Array<T>?>>()
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(typeOf<Array<Array<String>?>>(), typeOfArrayOfNArrayOf<String>())
|
||||
assertEquals(typeOf<Array<Array<String>?>>(), myTypeOf<Array<Array<String>?>>())
|
||||
assertEquals(typeOf<Array<Array<String>?>>(), myTypeOfArrayOfNArrayOf<String>())
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR, JS_IR_ES6
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.typeOf
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
inline fun <reified T> foo() =
|
||||
object { val x = typeOf<T>() }.x
|
||||
|
||||
inline fun <reified T> bar(expected: KType) {
|
||||
assertEquals(expected, foo<List<T>>())
|
||||
assertEquals(expected, object { val x = typeOf<List<T>>() }.x)
|
||||
assertEquals(expected, typeOf<List<T>>())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
bar<Int>(typeOf<List<Int>>())
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user