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:
Mads Ager
2019-01-28 13:34:51 +01:00
committed by max-kammerer
parent 37a149b218
commit bb0cd92da0
3 changed files with 4 additions and 2 deletions
@@ -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)
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
fun foo() {
if (test.lineNumber() > 0) {
test.lineNumber()