diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java index d7d477fef1a..273efa47442 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.java @@ -516,8 +516,11 @@ public class MethodInliner { } } else if (cur.getOpcode() == Opcodes.POP) { - LambdaInfo lambda = getLambdaIfExists(MethodInlinerUtilKt.singleOrNullInsn(StackTransformationUtilsKt.top(frame))); - if (lambda != null) { + SourceValue top = StackTransformationUtilsKt.top(frame); + LambdaInfo lambdaInfo = MethodInlinerUtilKt.getLambdaIfExistsAndMarkInstructions( + this, top, true, instructions, sources, toDelete + ); + if (lambdaInfo != null) { toDelete.add(cur); } } diff --git a/compiler/testData/codegen/boxInline/stackOnReturn/kt17591.kt b/compiler/testData/codegen/boxInline/stackOnReturn/kt17591.kt new file mode 100644 index 00000000000..c9a891f0e7d --- /dev/null +++ b/compiler/testData/codegen/boxInline/stackOnReturn/kt17591.kt @@ -0,0 +1,7 @@ +// FILE: 1.kt +inline fun alwaysOk(s: String, fn: (String) -> String): String { + return fn(return "OK") +} + +// FILE: 2.kt +fun box() = alwaysOk("what?") { it } \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/stackOnReturn/kt17591a.kt b/compiler/testData/codegen/boxInline/stackOnReturn/kt17591a.kt new file mode 100644 index 00000000000..adb5010e8c7 --- /dev/null +++ b/compiler/testData/codegen/boxInline/stackOnReturn/kt17591a.kt @@ -0,0 +1,7 @@ +// FILE: 1.kt +inline fun alwaysOk(s: String, fn: (String) -> String): String { + try { return fn(return "fail") } finally { fn(return "OK") } +} + +// FILE: 2.kt +fun box() = alwaysOk("what?") { it } \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/stackOnReturn/kt17591b.kt b/compiler/testData/codegen/boxInline/stackOnReturn/kt17591b.kt new file mode 100644 index 00000000000..672946db11d --- /dev/null +++ b/compiler/testData/codegen/boxInline/stackOnReturn/kt17591b.kt @@ -0,0 +1,15 @@ +// FILE: 1.kt +inline fun alwaysOk(s: String, fn: (String) -> String): String { + try { + throw Exception() + } + catch(e: Exception) { + fn(return "fail") + } + finally { + fn(return "OK") + } +} + +// FILE: 2.kt +fun box() = alwaysOk("what?") { it } \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 9a9efe63924..7a75c2ec08c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -2483,6 +2483,24 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("kt17591.kt") + public void testKt17591() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/kt17591.kt"); + doTest(fileName); + } + + @TestMetadata("kt17591a.kt") + public void testKt17591a() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/kt17591a.kt"); + doTest(fileName); + } + + @TestMetadata("kt17591b.kt") + public void testKt17591b() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/kt17591b.kt"); + doTest(fileName); + } + @TestMetadata("mixedTypesOnStack1.kt") public void testMixedTypesOnStack1() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/mixedTypesOnStack1.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index e76cae75a8c..2f73120a573 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -2483,6 +2483,24 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("kt17591.kt") + public void testKt17591() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/kt17591.kt"); + doTest(fileName); + } + + @TestMetadata("kt17591a.kt") + public void testKt17591a() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/kt17591a.kt"); + doTest(fileName); + } + + @TestMetadata("kt17591b.kt") + public void testKt17591b() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/kt17591b.kt"); + doTest(fileName); + } + @TestMetadata("mixedTypesOnStack1.kt") public void testMixedTypesOnStack1() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/stackOnReturn/mixedTypesOnStack1.kt");