Check that subject expression is evaluated only once

This commit is contained in:
Dmitry Petrov
2018-06-19 14:39:40 +03:00
parent 6194cfc782
commit a7492e91c9
6 changed files with 47 additions and 0 deletions
@@ -0,0 +1,22 @@
// !LANGUAGE: +VariableDeclarationInWhenSubject
// IGNORE_BACKEND: JS
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"
}