Don't remove checkcast for reified values
#KT-35511 Fixed
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// JVM_TARGET: 1.8
|
||||
// FILE: 1.kt
|
||||
// WITH_RUNTIME
|
||||
|
||||
package test
|
||||
|
||||
open class Base(val name: String)
|
||||
class A(name: String) : Base(name)
|
||||
class B(name: String) : Base(name)
|
||||
|
||||
var result = "fail"
|
||||
|
||||
fun foo(base: Array<out Base>) {
|
||||
result = base[0].name
|
||||
}
|
||||
|
||||
fun cond() = true
|
||||
|
||||
inline fun <reified T : Base, reified Y : Base> process(a: Base) {
|
||||
val z = if (cond())
|
||||
arrayOf<T>(a as T)
|
||||
else
|
||||
arrayOf<Y>(a as Y)
|
||||
foo(z)
|
||||
}
|
||||
|
||||
|
||||
// FILE: 2.kt
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
process<A, B>(A("OK"))
|
||||
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// JVM_TARGET: 1.8
|
||||
// FILE: 1.kt
|
||||
// WITH_RUNTIME
|
||||
|
||||
package test
|
||||
|
||||
open class Base(val name: String)
|
||||
class A(name: String) : Base(name)
|
||||
class B(name: String) : Base(name)
|
||||
|
||||
var result = "fail"
|
||||
|
||||
fun foo(base: Array<out Base>) {
|
||||
result = base[0].name
|
||||
}
|
||||
|
||||
fun cond() = true
|
||||
|
||||
inline fun <reified T : Base, reified Y : Base> process(a: Base) {
|
||||
val z = try {
|
||||
arrayOf<T>(a as T)
|
||||
} catch (e: Exception) {
|
||||
arrayOf<Y>(a as Y)
|
||||
}
|
||||
|
||||
foo(z)
|
||||
}
|
||||
|
||||
|
||||
// FILE: 2.kt
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
process<A, B>(B("OK"))
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user