Files
kotlin-fork/nj2k/testData/newJ2k/nullability/notNullCast.kt
T
2019-09-29 11:39:36 +03:00

25 lines
555 B
Kotlin
Vendored

class Passenger {
open class PassParent
class PassChild : PassParent()
fun provideNullable(p: Int): PassParent? {
return if (p > 0) PassChild() else null
}
fun test1() {
val pass = provideNullable(1)!!
accept1(pass as PassChild)
}
fun test2() {
val pass = provideNullable(1)
if (1 == 2) {
assert(pass != null)
accept2(pass as PassChild?)
}
accept2(pass as PassChild?)
}
fun accept1(p: PassChild?) {}
fun accept2(p: PassChild?) {}
}