KT-9644: override default behavior for non-local return in FixStackAnalyzer
This commit is contained in:
+5
@@ -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)
|
||||
|
||||
+21
@@ -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()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun foo() {
|
||||
with(1) {
|
||||
return (1..2).forEach { it }
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo()
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -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");
|
||||
|
||||
+6
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user