Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/varnotnull/forEach.fir.kt
T
Dmitriy Novozhilov 6735cc8937 [FIR] Implement new bound smartcast algorithm
#KT-36055 Fixed
2020-02-12 10:17:45 +03:00

17 lines
409 B
Kotlin
Vendored

// !WITH_NEW_INFERENCE
data class SomeObject(val n: SomeObject?) {
fun doSomething() {}
fun next(): SomeObject? = n
}
fun list(start: SomeObject): SomeObject {
var e: SomeObject? = start
for (i in 0..42) {
// Unsafe calls because of nullable e at the beginning
e.doSomething()
e = e.next()
}
// Smart cast is not possible here due to next()
return e
}