[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.
This commit is contained in:
committed by
Alexander Udalov
parent
91581d6c1a
commit
05ff2b1292
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class BigEnum {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class Season {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class Season {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
package abc.foo
|
||||
|
||||
enum class Season {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
enum class Season {
|
||||
WINTER,
|
||||
SPRING,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// IGNORE_BACKEND: JVM
|
||||
|
||||
fun test(x: Int): String {
|
||||
when {
|
||||
x == 1 || x == 3 || x == 5 -> "135"
|
||||
x == 2 || x == 4 || x == 6 -> "246"
|
||||
else -> "other"
|
||||
}
|
||||
}
|
||||
|
||||
// 1 TABLESWITCH
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
enum class Season {
|
||||
|
||||
Reference in New Issue
Block a user