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

37 lines
811 B
Kotlin
Vendored

// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun getBoolean() = true
fun testSafeCaptureVarInInitializer() {
var x: Int? = 42
x!!
x.inc()
val s = when (val y = run { x = 42; 32 }) {
0 -> {
x.inc() // TODO fix smart casts for captured variables
"0"
}
else -> "!= 0"
}
x.inc() // TODO fix smart casts for captured variables
}
fun testUnsafeCaptureVarInInitializer() {
var x: Int? = 42
x!!
x.inc()
val s = when (val y = run { x = null; 32 }) {
0 -> {
x.<!INAPPLICABLE_CANDIDATE!>inc<!>() // NB smart cast should be impossible
"0"
}
else -> "!= 0"
}
x.<!INAPPLICABLE_CANDIDATE!>inc<!>() // NB smart cast should be impossible
}