Support 'when' with subject variable in JVM BE
This commit is contained in:
+17
@@ -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()
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: +VariableDeclarationInWhenSubject
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
val x = 1
|
||||
|
||||
fun box() =
|
||||
when (val y = x) {
|
||||
1 -> "OK"
|
||||
else -> "Fail: $y"
|
||||
}
|
||||
+10
@@ -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"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !LANGUAGE: +VariableDeclarationInWhenSubject
|
||||
|
||||
val x = 1
|
||||
|
||||
fun box() =
|
||||
when (val y = x) {
|
||||
in 0..2 -> "OK"
|
||||
else -> "Fail: $y"
|
||||
}
|
||||
Reference in New Issue
Block a user