Files
kotlin/compiler/testData/codegen/box/when/whenSafeCallSubjectEvaluatedOnce.kt
2019-11-19 11:00:09 +03:00

20 lines
425 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
var subjectEvaluated = 0
fun String.foo() = length.also { ++subjectEvaluated }
fun test(s: String?) =
when (s?.foo()) {
0 -> "zero"
1 -> "one"
2 -> "two"
else -> "other"
}
fun box(): String {
val t = test("12")
if (t != "two") return "Fail: $t"
if (subjectEvaluated != 1) return "Fail: subjectEvaluated=$subjectEvaluated"
return "OK"
}