Add some data flow analysis tests on when

This commit is contained in:
Dmitry Savvinov
2018-06-08 11:29:27 +03:00
committed by Dmitry Petrov
parent ae929d0f08
commit 148d03e365
10 changed files with 213 additions and 0 deletions
@@ -0,0 +1,37 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun getBoolean() = true
fun testSafeCaptureVarInInitializer() {
var x: Int? = 42
x!!
<!DEBUG_INFO_SMARTCAST!>x<!>.inc()
val s = when (val y = run { x = 42; 32 }) {
0 -> {
<!SMARTCAST_IMPOSSIBLE!>x<!>.inc() // TODO fix smart casts for captured variables
"0"
}
else -> "!= 0"
}
<!SMARTCAST_IMPOSSIBLE!>x<!>.inc() // TODO fix smart casts for captured variables
}
fun testUnsafeCaptureVarInInitializer() {
var x: Int? = 42
x!!
<!DEBUG_INFO_SMARTCAST!>x<!>.inc()
val s = when (val y = run { x = null; 32 }) {
0 -> {
<!SMARTCAST_IMPOSSIBLE!>x<!>.inc() // NB smart cast should be impossible
"0"
}
else -> "!= 0"
}
<!SMARTCAST_IMPOSSIBLE!>x<!>.inc() // NB smart cast should be impossible
}