Files
kotlin-fork/compiler/testData/diagnostics/tests/smartCasts/varnotnull/capturedInClosureModifiedBefore.fir.kt
T
pyos 1aae586238 FIR DFA: don't erase statements when entering non-call-in-place lambda
Instead, rely on the variable assignment analyzer to properly restrict
smart casts. This makes error messages more consistent, but otherwise
should have no effect.
2023-01-10 15:40:51 +02:00

61 lines
993 B
Kotlin
Vendored

// !LANGUAGE: +CapturedInClosureSmartCasts
fun run(f: () -> Unit) = f()
fun foo(s: String?) {
var x: String? = null
if (s != null) {
x = s
}
if (x != null) {
run {
x.hashCode()
}
}
}
fun bar(s: String?) {
var x = s
if (x != null) {
run {
x.hashCode()
}
}
}
fun baz(s: String?) {
var x = s
if (x != null) {
run {
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
}
run {
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
x = null
}
}
}
fun gaz(s: String?) {
var x = s
if (x != null) {
run {
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
x = null
}
run {
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
}
}
}
fun gav(s: String?) {
var x = s
if (x != null) {
run {
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
}
x = null
}
}