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 c146a705d74..4331a1afcbf 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 @@ -33,7 +33,6 @@ 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.IrType -import org.jetbrains.kotlin.ir.types.isMarkedNullable import org.jetbrains.kotlin.ir.types.toKotlinType import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementVisitor @@ -1033,6 +1032,14 @@ class ExpressionCodegen( val tryBlockStart = markNewLabel() mv.nop() gen(aTry.tryResult, aTry.asmType, data) + + val isExpression = true //TODO: more wise check is required + var savedValue: Local? = null + if (isExpression) { + savedValue = local(frame.enterTemp(aTry.asmType), aTry.asmType) + savedValue.store(onStack(aTry.asmType), mv) + } + val tryBlockEnd = markNewLabel() val tryRegions = getCurrentTryIntervals(tryInfo, tryBlockStart, tryBlockEnd) @@ -1056,6 +1063,10 @@ class ExpressionCodegen( catchBody.markLineNumber(true) gen(catchBody, catchBody.asmType, data) + savedValue?.let { + savedValue.store(onStack(aTry.asmType), mv) + } + frame.leave(clause.catchParameter) val clauseEnd = markNewLabel() @@ -1096,6 +1107,11 @@ class ExpressionCodegen( } mv.mark(tryCatchBlockEnd) + + savedValue?.let { + savedValue.put(mv) + frame.leaveTemp(aTry.asmType) + } return aTry.onStack } diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/finallyInFinally2.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/finallyInFinally2.kt index 51bd4b7ea84..8b4b28414fe 100644 --- a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/finallyInFinally2.kt +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/finallyInFinally2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: 1.kt package test diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex3.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex3.kt index d4e7d9ae973..90cfc9e8785 100644 --- a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex3.kt +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex3.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: 1.kt package test diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex4.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex4.kt index 044ea148929..3b507b537bd 100644 --- a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex4.kt +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained/intReturnComplex4.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: 1.kt package test diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite/returnInFinally.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite/returnInFinally.kt index 17295437286..11e1e00e537 100644 --- a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite/returnInFinally.kt +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/declSite/returnInFinally.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: 1.kt package test diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/nestedWithReturns.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/nestedWithReturns.kt index d8ff794b13d..6539f8bc4bc 100644 --- a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/nestedWithReturns.kt +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/nestedWithReturns.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: 1.kt package test diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/tryCatchInFinally.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/tryCatchInFinally.kt index 39030f50187..f263407c3d2 100644 --- a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/tryCatchInFinally.kt +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/exceptionTable/tryCatchInFinally.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR // FILE: 1.kt package test diff --git a/compiler/testData/codegen/bytecodeText/statements/tryCatchFinally.kt b/compiler/testData/codegen/bytecodeText/statements/tryCatchFinally.kt index 31145f208fe..38e80522bbf 100644 --- a/compiler/testData/codegen/bytecodeText/statements/tryCatchFinally.kt +++ b/compiler/testData/codegen/bytecodeText/statements/tryCatchFinally.kt @@ -1,3 +1,4 @@ +// IGNORE_BACKEND: JVM_IR fun z() {} fun foo() {