From b902da55d57860c1104ed8bdc9bb1c28e7b7362f Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Thu, 7 Feb 2019 15:19:08 +0100 Subject: [PATCH] JVM_IR: Block with nothing type do not generate values on the stack. --- .../kotlin/backend/jvm/codegen/ExpressionCodegen.kt | 5 ++--- .../functions/tailRecursion/returnInIfInFinally.kt | 1 - .../testData/codegen/box/regressions/typeCastException.kt | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index af1bac0a72d..acd9db48e4c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -243,13 +243,12 @@ 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) } + // Blocks with nothing type do not generate a value on the stack. + if (expression.type.isNothing()) return none() return coerceNotToUnit(result.type, result.kotlinType, expression.type.toKotlinType()) } diff --git a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/returnInIfInFinally.kt b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/returnInIfInFinally.kt index 57ad0961acb..bf4f081b6f3 100644 --- a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/returnInIfInFinally.kt +++ b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/returnInIfInFinally.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: JS_IR // TODO: muted automatically, investigate should it be ran for JS or not // DONT_RUN_GENERATED_CODE: JS diff --git a/compiler/testData/codegen/box/regressions/typeCastException.kt b/compiler/testData/codegen/box/regressions/typeCastException.kt index 108002836dc..4ab35fa6585 100644 --- a/compiler/testData/codegen/box/regressions/typeCastException.kt +++ b/compiler/testData/codegen/box/regressions/typeCastException.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME