Use experimental javaType in full reflect where it's not supported yet
#KT-22936 Fixed #KT-34344 Fixed
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.reflect.full.allSupertypes
|
||||
import kotlin.reflect.jvm.javaType
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
interface I<T>
|
||||
|
||||
abstract class A<X> : Map<I<out CharSequence>, Array<List<Int>>>
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(
|
||||
"java.util.Map<test.I<? extends java.lang.CharSequence>, java.util.List<? extends java.lang.Integer>[]>",
|
||||
A::class.allSupertypes.single { it.classifier == Map::class }.javaType.toString()
|
||||
)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
import kotlin.reflect.KTypeProjection
|
||||
import kotlin.reflect.full.createType
|
||||
import kotlin.reflect.jvm.javaType
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A<X>
|
||||
|
||||
fun box(): String {
|
||||
val nullableAOfInString = A::class.createType(listOf(
|
||||
KTypeProjection.contravariant(String::class.createType())
|
||||
), true)
|
||||
assertEquals("test.A<? super java.lang.String>", nullableAOfInString.javaType.toString())
|
||||
|
||||
val arrayOfListOfInteger = Array::class.createType(listOf(
|
||||
KTypeProjection.invariant(List::class.createType(listOf(
|
||||
KTypeProjection.invariant(Int::class.createType())
|
||||
)))
|
||||
))
|
||||
assertEquals("java.util.List<java.lang.Integer>[]", arrayOfListOfInteger.javaType.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.lang.reflect.TypeVariable
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A<T> {
|
||||
class A<T : CharSequence> {
|
||||
fun foo(t: T) {}
|
||||
}
|
||||
|
||||
@@ -19,5 +19,8 @@ fun box(): String {
|
||||
assertEquals("T", t.name)
|
||||
assertEquals(A::class.java, (t.genericDeclaration as Class<*>))
|
||||
|
||||
val tp = A::class.typeParameters
|
||||
assertEquals(CharSequence::class.java, tp.single().upperBounds.single().javaType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user