Files
kotlin-fork/compiler/testData/codegen/bytecodeText/whenEnumOptimization/withoutElse.kt
T
Mads Ager 05ff2b1292 [JVM_IR] Extend when to switch translation to deal with nested ors.
FIR translates:

```
when (x) {
  1, 2, 3 -> action
  else -> other_action
}
```

to an IR structure with nested ors:

```
if ((x == 1 || x == 2) || (x == 3)) action
else other_action
```

This change allows that to turn into switch instructions in the
JVM backend.
2021-02-16 03:20:07 -08:00

31 lines
610 B
Kotlin
Vendored

import kotlin.test.assertEquals
enum class Season {
WINTER,
SPRING,
SUMMER,
AUTUMN
}
fun bar1(x : Season) : String {
when (x) {
Season.WINTER, Season.SPRING -> return "winter_spring"
Season.SPRING -> return "spring"
Season.SUMMER -> return "summer"
}
return "autumn"
}
fun bar2(x : Season) : String {
when (x) {
Season.WINTER, Season.SPRING -> return "winter_spring"
Season.SPRING -> return "spring"
Season.SUMMER -> return "summer"
Season.AUTUMN -> return "autumn"
}
return "fail unknown"
}
// 2 TABLESWITCH