Files
kotlin-fork/compiler/testData/codegen/boxInline/reified/checkCast/kt8043.kt
T
Alexander Udalov f48bdc1fcb Fix codegen box tests for language version 1.4
Since API version 1.4, NullPointerException is thrown for casts of null
to any type instead of TypeCastException.
2020-01-20 19:12:59 +01:00

27 lines
389 B
Kotlin
Vendored

// FILE: 1.kt
// WITH_RUNTIME
package test
inline fun <reified T, reified R>T.castTo(): R = this as R
// FILE: 2.kt
import test.*
fun case1(): Int =
null.castTo<Int?, Int>()
fun box(): String {
failNPE { case1(); return "Fail" }
return "OK"
}
inline fun failNPE(s: () -> Unit) {
try {
s()
}
catch (e: NullPointerException) {
// OK
}
}