Files
kotlin-fork/compiler/testData/codegen/box/when/whenSubjectVariable/captureSubjectVariable.kt
T
2018-06-28 12:26:41 +02:00

18 lines
341 B
Kotlin
Vendored

// !LANGUAGE: +VariableDeclarationInWhenSubject
// IGNORE_BACKEND: JVM_IR
// 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()
}