Fix for KT-11081: Reified type parameters are lost in anonymous object in inline function when using default value parameters

#KT-11081 Fixed
This commit is contained in:
Michael Bogdanov
2016-02-18 15:23:39 +03:00
parent 4c1c64fa08
commit 405c21a17e
5 changed files with 57 additions and 3 deletions
@@ -0,0 +1,17 @@
import test.*
fun specifyOptionalArgument() = typeWithMessage<List<Int>>("Hello")
fun useDefault() = typeWithMessage<List<Int>>()
fun box(): String {
val specifyOptionalArgument = specifyOptionalArgument()
val useDefault = useDefault()
if (useDefault != specifyOptionalArgument) return "fail: $useDefault != $specifyOptionalArgument"
val type = typeWithMessage<List<Int>>("")
if (type != " test.TypeRef<java.util.List<? extends java.lang.Integer>>") return "fail 2: $type"
return "OK"
}
@@ -0,0 +1,21 @@
package test
open class TypeRef<T> {
val type = target()
private fun target(): String {
val thisClass = this.javaClass
val superClass = thisClass.genericSuperclass
return superClass.toString()
}
}
inline fun <reified T> typeWithMessage(message: String = "Hello"): String {
val type = object : TypeRef<T>() {}
val target = type.type
return message + " " + target
}