diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt index 6f8daf431eb..523685222ec 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/fixStack/FixStackAnalyzer.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil import org.jetbrains.kotlin.codegen.optimization.common.MethodAnalyzer import org.jetbrains.kotlin.codegen.optimization.common.OptimizationBasicInterpreter import org.jetbrains.kotlin.codegen.pseudoInsns.PseudoInsn +import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode import org.jetbrains.org.objectweb.asm.tree.JumpInsnNode import org.jetbrains.org.objectweb.asm.tree.MethodNode @@ -73,6 +74,10 @@ public class FixStackAnalyzer( executeBeforeInlineCallMarker(insn) InlineCodegenUtil.isAfterInlineMarker(insn) -> executeAfterInlineCallMarker(insn) + InlineCodegenUtil.isMarkedReturn(insn) -> { + // KT-9644: might throw "Incompatible return type" on non-local return, in fact we don't care. + if (insn.opcode == Opcodes.RETURN) return + } } super.execute(insn, interpreter) diff --git a/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/kt9644try.kt b/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/kt9644try.kt new file mode 100644 index 00000000000..63921992a06 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/kt9644try.kt @@ -0,0 +1,21 @@ +inline fun doCall(f: () -> Any) = f() + +fun test1() { + val localResult = doCall { + try { "1" } catch (e: Exception) { "2" } + return + } +} + +fun test2(): String { + val localResult = doCall { + try { "1" } catch (e: Exception) { "2" } + return@test2 "OK" + } + return "Hmmm..." +} + +fun box(): String { + test1() + return test2() +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/inline/kt9644let.kt b/compiler/testData/codegen/boxWithStdlib/inline/kt9644let.kt new file mode 100644 index 00000000000..d12593090b5 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/inline/kt9644let.kt @@ -0,0 +1,10 @@ +fun foo() { + with(1) { + return (1..2).forEach { it } + } +} + +fun box(): String { + foo() + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 7672e071332..057a1b85412 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -2460,6 +2460,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt9644try.kt") + public void testKt9644try() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/kt9644try.kt"); + doTest(fileName); + } + @TestMetadata("multipleCatchBlocks.kt") public void testMultipleCatchBlocks() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/multipleCatchBlocks.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index dd56c2dd071..f2681771b99 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -1938,6 +1938,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/inline/kt6895.kt"); doTestWithStdlib(fileName); } + + @TestMetadata("kt9644let.kt") + public void testKt9644let() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/inline/kt9644let.kt"); + doTestWithStdlib(fileName); + } } @TestMetadata("compiler/testData/codegen/boxWithStdlib/intrinsics")