Files
kotlin-fork/compiler/testData/codegen/box/when/switchOptimizationWithGap.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

34 lines
856 B
Kotlin
Vendored

// WITH_STDLIB
// CHECK_CASES_COUNT: function=foo count=4 TARGET_BACKENDS=JS
// CHECK_CASES_COUNT: function=foo count=0 IGNORED_BACKENDS=JS
// CHECK_IF_COUNT: function=foo count=1 TARGET_BACKENDS=JS
// CHECK_IF_COUNT: function=foo count=0 IGNORED_BACKENDS=JS
var log = ""
fun foo(x: Int): String {
log += "foo($x);"
return when (x) {
1 -> "one"
2 -> "two"
three(x) -> "three"
4 -> "four"
5 -> "five"
else -> "many"
}
}
fun three(x: Int): Int {
log += "three($x);"
return 3
}
fun box(): String {
var result = (1..7).map(::foo).joinToString()
if (result != "one, two, three, four, five, many, many") return "fail1: $result"
if (log != "foo(1);foo(2);foo(3);three(3);foo(4);three(4);foo(5);three(5);foo(6);three(6);foo(7);three(7);") return "fail2: $log"
return "OK"
}