Files
kotlin/compiler/testData/codegen/box/when/whenSubjectVariable/subjectExpressionIsEvaluatedOnce.kt
Zalim Bashorov 3c765e3625 [JS BE] Support val in when subject
#KT-25014 Fixed
2018-08-09 16:22:25 +03:00

21 lines
425 B
Kotlin
Vendored

// !LANGUAGE: +VariableDeclarationInWhenSubject
var effectCount = 0
fun withSideEffect(): Any {
effectCount++
return 42
}
fun box(): String {
when (val y = withSideEffect()) {
1 -> throw AssertionError()
"" -> throw AssertionError()
is String -> throw AssertionError()
42 -> {}
}
if (effectCount != 1) throw AssertionError("effectCount=$effectCount")
return "OK"
}