diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/CoveringTryCatchNodeProcessor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/CoveringTryCatchNodeProcessor.kt index 7320c9f2ba8..baf41a4e7c3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/CoveringTryCatchNodeProcessor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/CoveringTryCatchNodeProcessor.kt @@ -121,6 +121,13 @@ class IntervalMetaInfo> { return currentIntervals.map { split(it, by, keepStart) } } + fun splitAndRemoveIntervalsFromCurrents(by : Interval) { + val copies = ArrayList(currentIntervals) + copies.forEach { + splitAndRemoveInterval(it, by, true) + } + } + fun processCurrent(curIns: LabelNode, directOrder: Boolean) { getInterval(curIns, directOrder).forEach { val added = currentIntervals.add(it) @@ -193,16 +200,16 @@ public class LocalVarNodeWrapper(val node: LocalVariableNode) : Interval, Splitt override val endLabel: LabelNode get() = node.end - override fun split(split: Interval, keepStart: Boolean): SplitPair { + override fun split(splitBy: Interval, keepStart: Boolean): SplitPair { val newPartInterval = if (keepStart) { val oldEnd = endLabel - node.end = split.startLabel - Pair(split.endLabel, oldEnd) + node.end = splitBy.startLabel + Pair(splitBy.endLabel, oldEnd) } else { val oldStart = startLabel - node.start = split.endLabel - Pair(oldStart, split.startLabel) + node.start = splitBy.endLabel + Pair(oldStart, splitBy.startLabel) } return SplitPair(this, LocalVarNodeWrapper( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java index 91e203c14b8..c4a043c4898 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -700,7 +700,7 @@ public class InlineCodegen extends CallGenerator { SimpleInterval splitBy = new SimpleInterval((LabelNode) start.info, extension.finallyIntervalEnd); processor.getTryBlocksMetaInfo().splitCurrentIntervals(splitBy, true); - processor.getLocalVarsMetaInfo().splitCurrentIntervals(splitBy, true); + //processor.getLocalVarsMetaInfo().splitAndRemoveIntervalsFromCurrents(splitBy); mark.dropTo(); } diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.1.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.1.kt new file mode 100644 index 00000000000..951e9225d4f --- /dev/null +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.1.kt @@ -0,0 +1,35 @@ +import test.* + +fun test1(): String { + try { + doCall { + try { + doCall { + val a = 1 + if (1 == 1) { + return "a" + } + else if (2 == 2) { + return "b" + } + } + + return "d" + } + finally { + "1" + } + } + + } + finally { + "2" + } + return "f" +} + +fun box(): String { + test1() + + return "OK" +} diff --git a/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.2.kt b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.2.kt new file mode 100644 index 00000000000..12d90f9709d --- /dev/null +++ b/compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.2.kt @@ -0,0 +1,5 @@ +package test + +public inline fun doCall(block: ()-> R) : R { + return block() +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java index 134d2c5c45f..2a7a88830fd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxInlineCodegenTestGenerated.java @@ -658,6 +658,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/finallyInFinally.1.kt"); doTestMultiFileWithInlineCheck(fileName); } + + @TestMetadata("wrongVarInterval.1.kt") + public void testWrongVarInterval() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.1.kt"); + doTestMultiFileWithInlineCheck(fileName); + } } @TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained") diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java index 0e45e8887fc..873a5c4a1cc 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -658,6 +658,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/finallyInFinally.1.kt"); doBoxTestWithInlineCheck(fileName); } + + @TestMetadata("wrongVarInterval.1.kt") + public void testWrongVarInterval() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/callSite/wrongVarInterval.1.kt"); + doBoxTestWithInlineCheck(fileName); + } } @TestMetadata("compiler/testData/codegen/boxInline/nonLocalReturns/tryFinally/chained")