Reflection: change order of arguments of inner generic type

As in KClassifier.createType and everywhere in the compiler, specify arguments
for the innermost type first. This is more convenient to use because generally
the construction/introspection of such type starts from the innermost class
anyway (i.e. something like generateSequence can be used, without the need to
call .reverse() in the end)
This commit is contained in:
Alexander Udalov
2016-08-02 13:28:49 -07:00
parent 89d69bc7eb
commit a7f4037206
7 changed files with 95 additions and 10 deletions
@@ -0,0 +1,28 @@
// WITH_REFLECT
import kotlin.reflect.jvm.javaType
import kotlin.test.assertEquals
class Outer<A, B> {
inner class Inner<C, D> {
inner class Innermost<E, F>
}
}
fun foo(): Outer<Int, Number>.Inner<String, Float>.Innermost<Any, Any?> = null!!
fun box(): String {
assertEquals(
listOf(
Any::class.java,
Any::class.java,
String::class.java,
Float::class.javaObjectType,
Int::class.javaObjectType,
Number::class.java
),
::foo.returnType.arguments.map { it.type!!.javaType }
)
return "OK"
}
@@ -0,0 +1,32 @@
// WITH_REFLECT
import kotlin.test.*
class Outer<A, B> {
inner class Inner<C, D> {
inner class Innermost<E, F>
}
}
fun foo(): Outer<Int, Number>.Inner<String, Float>.Innermost<Any, Any?> = null!!
fun box(): String {
val types = ::foo.returnType.arguments.map { it.type!! }
assertEquals(
listOf(
Any::class,
Any::class,
String::class,
Float::class,
Int::class,
Number::class
),
types.map { it.classifier }
)
assertFalse(types[0].isMarkedNullable)
assertTrue(types[1].isMarkedNullable)
return "OK"
}