Support 'when' with subject variable in JVM BE

This commit is contained in:
Dmitry Petrov
2018-06-08 12:51:33 +03:00
parent 148d03e365
commit d6894091a9
9 changed files with 225 additions and 24 deletions
@@ -0,0 +1,17 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// IGNORE_BACKEND: JS
fun box(): String {
var y: String = "OK"
var materializer: (() -> String)? = null
when (val x = y) {
"OK" -> materializer = { x }
else -> return "x is $x"
}
y = "Fail"
return materializer!!.invoke()
}
@@ -0,0 +1,10 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// IGNORE_BACKEND: JS
val x = 1
fun box() =
when (val y = x) {
1 -> "OK"
else -> "Fail: $y"
}
@@ -0,0 +1,10 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// IGNORE_BACKEND: JS
val x: Any = 1
fun box() =
when (val y = x) {
is Int -> "OK"
else -> "Fail: $y"
}
@@ -0,0 +1,9 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
val x = 1
fun box() =
when (val y = x) {
in 0..2 -> "OK"
else -> "Fail: $y"
}