JVM_IR: Fix codegeneration for missing branches.
This used to generate an ACONST_NULL instruction leading to incorrect stack height for code such as: ``` if (condition) else 32 ```
This commit is contained in:
+4
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.isNothing
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
import org.jetbrains.kotlin.ir.util.isNullConst
|
||||
@@ -240,6 +241,9 @@ class ExpressionCodegen(
|
||||
}
|
||||
|
||||
override fun visitContainerExpression(expression: IrContainerExpression, data: BlockInfo): StackValue {
|
||||
// Empty blocks with nothing type should not generate a value on the stack. They
|
||||
// arise for if statements with missing branches such as: if (expr) else 42
|
||||
if (expression.statements.size == 0 && expression.type.isNothing()) return none()
|
||||
val result = expression.statements.fold(none()) { _, exp ->
|
||||
//coerceNotToUnit(r.type, Type.VOID_TYPE)
|
||||
exp.accept(this, data)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// FILE: list.kt
|
||||
|
||||
val intList = listOf(1, 2, 3)
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
fun foo() {
|
||||
if (test.lineNumber() > 0) {
|
||||
test.lineNumber()
|
||||
|
||||
Reference in New Issue
Block a user