Files
kotlin-fork/compiler/testData/codegen/box/casts/kt50577.kt
T
Dmitry Petrov 4ad6cfcf53 JVM_IR fix cast to not-null type
We can't rely on argument type nullability here, because it still can
hold an uninitialized value on JVM.

KT-50577 KT-35272 KT-27427
2021-12-30 13:41:17 +03:00

27 lines
386 B
Kotlin
Vendored

abstract class A {
abstract val x: Any
init {
castX(this)
}
}
class B : A() {
override val x: Any = "abc"
}
fun castX(a: A) {
a.x as String
}
fun box(): String {
try {
B()
} catch (e: NullPointerException) {
return "OK"
} catch (e: ClassCastException) {
return "OK" // JS
}
return "Failed: should throw NPE"
}