FIR2IR: never generate empty when #KT-55459 Fixed

In details, this commit changes the following:
- it converts FIR when without branches to empty IR block without when
- it doesn't drop empty else branches in when anymore
This commit is contained in:
Mikhail Glukhikh
2023-01-24 16:31:14 +01:00
committed by Space Team
parent b026678a34
commit ae4b8be16b
11 changed files with 85 additions and 9 deletions
@@ -0,0 +1,21 @@
FILE fqName:<root> fileName:/emptyWhen.kt
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
BLOCK type=kotlin.Unit origin=WHEN
VAR name:x type:kotlin.Int [val]
CONST Int type=kotlin.Int value=0
BLOCK type=kotlin.Unit origin=WHEN
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int [val]
GET_VAR 'val x: kotlin.Int [val] declared in <root>.foo' type=kotlin.Int origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: BLOCK type=kotlin.Unit origin=null
VAR name:z type:kotlin.Unit [val]
BLOCK type=kotlin.Unit origin=WHEN
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val]
GET_VAR 'val x: kotlin.Int [val] declared in <root>.foo' type=kotlin.Int origin=null
WHEN type=kotlin.Unit origin=WHEN
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: BLOCK type=kotlin.Unit origin=null
+11
View File
@@ -0,0 +1,11 @@
// FIR_IDENTICAL
fun foo() {
when {}
val x = 0
when (x) {
else -> {}
}
val z = when (x) {
else -> {}
}
}
@@ -0,0 +1,20 @@
fun foo() {
{ // BLOCK
}
val x: Int = 0
{ // BLOCK
val tmp0_subject: Int = x
when {
else -> { // BLOCK
}
}
}
val z: Unit = { // BLOCK
val tmp1_subject: Int = x
when {
else -> { // BLOCK
}
}
}
}