55ae6d1f3e
For this code:
```
enum class Season {
WINTER,
SPRING,
SUMMER,
AUTUMN
}
fun bar1(x : Season) : String {
return when (x) {
Season.WINTER, Season.SPRING -> "winter_spring"
Season.SUMMER -> "summer"
else -> "autumn"
}
}
```
previously we generated this:
```
function foo(x) {
var tmp0_subject = x;
return (tmp0_subject.equals(Season_WINTER_getInstance())
? true
: tmp0_subject.equals(Season_SPRING_getInstance()))
? 'winter_spring'
: tmp0_subject.equals(Season_SUMMER_getInstance())
? 'summer'
: 'autumn';
}
```
And now we generated this:
```
function bar2(x) {
var tmp0_subject = x;
var tmp0 = tmp0_subject._get_ordinal__0_k$();
var tmp;
switch (tmp0) {
case 0:
case 1:
tmp = 'winter_spring';
break;
case 2:
tmp = 'summer';
break;
case 3:
tmp = 'autumn';
break;
default:
noWhenBranchMatchedException();
break;
}
return tmp;
}
```
25 lines
469 B
Kotlin
Vendored
25 lines
469 B
Kotlin
Vendored
// CHECK_CASES_COUNT: function=box count=6
|
|
// CHECK_IF_COUNT: function=box count=1
|
|
|
|
enum class En { A, B, C }
|
|
|
|
fun box(): String {
|
|
var res = ""
|
|
// nullable variable
|
|
val en2: Any? = En.A
|
|
if (en2 is En) {
|
|
when (en2) {
|
|
En.A -> {res += "O"}
|
|
En.B -> {}
|
|
En.C -> {}
|
|
}
|
|
|
|
when (en2 as En) {
|
|
En.A -> {res += "K"}
|
|
En.B -> {}
|
|
En.C -> {}
|
|
}
|
|
}
|
|
|
|
return res
|
|
} |