Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/lambdaAndArgumentFun.kt
T
Mikhail Glukhikh 4b35e3b135 Preliminary declaration visitor for estimating local variable's predictability for smart casts
Predictability estimation algorithm is completely new, but backward compatibility should present.
A large set of tests. Some updated tests.
Smart casts allowed for captured variables if they are not modified in closure #KT-9051 Fixed
Also #KT-8643 Fixed
Also #KT-7976 Fixed
Correct handling of lambda arguments in functions #KT-9143 Fixed
2015-10-16 20:47:47 +03:00

15 lines
440 B
Kotlin
Vendored

// !DIAGNOSTICS: -NOTHING_TO_INLINE
// See KT-9143: smart cast on a variable nulled inside a lambda argument
inline fun <T> foo(t1: T, t2: T) = t1 ?: t2
inline fun <T> bar(<!UNUSED_PARAMETER!>l<!>: (T) -> Unit): T = null!!
fun use() {
var x: Int?
x = 5
// Write to x is AFTER
<!DEBUG_INFO_SMARTCAST!>x<!>.hashCode()
// No smart cast should be here!
foo(bar { x = null }, <!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode())
}