Fix for KT-11677: Generic type signatures for local classes in inlined lambdas are not written properly

#KT-11677 Fixed
This commit is contained in:
Michael Bogdanov
2016-04-03 16:24:48 +03:00
parent f5166b7aef
commit e0adfd453f
4 changed files with 47 additions and 2 deletions
+33
View File
@@ -0,0 +1,33 @@
// FILE: 1.kt
// FULL_JDK
// WITH_REFLECT
package test
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
open class TypeLiteral<T> {
val type: Type
get() = (javaClass.genericSuperclass as ParameterizedType).getActualTypeArguments()[0]
}
// normal inline function works fine
inline fun <reified T> typeLiteral(): TypeLiteral<T> = object : TypeLiteral<T>() {}
// nested lambda loses reification of T
inline fun <reified T> brokenTypeLiteral(): TypeLiteral<T> = "".run { typeLiteral<T>() }
// FILE: 2.kt
import test.*
fun box(): String {
val type1 = typeLiteral<List<String>>().type.toString()
if (type1 != "java.util.List<? extends java.lang.String>") return "fail 1: $type1"
val type2 = brokenTypeLiteral<List<String>>().type.toString()
if (type2 != "java.util.List<? extends java.lang.String>") return "fail 2: $type2"
return "OK"
}