KT-6646, KT-10482:

when a method (or a property getter) returns Nothing, emit
  ACONST_NULL
  ATHROW
after a call so that class files verifier knows that this is an exit point in a method.
Note that if an inline method returning Nothing throws an exception explicitly
(or via a chain of inline methods), this code will be deleted by DCE.
This commit is contained in:
Dmitry Petrov
2015-12-30 16:02:48 +03:00
parent ffd1bcf72f
commit b736880787
12 changed files with 188 additions and 0 deletions
@@ -706,6 +706,24 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/inline"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("inlineReturnsNothing1.kt")
public void testInlineReturnsNothing1() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing1.kt");
doTest(fileName);
}
@TestMetadata("inlineReturnsNothing2.kt")
public void testInlineReturnsNothing2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing2.kt");
doTest(fileName);
}
@TestMetadata("inlineReturnsNothing3.kt")
public void testInlineReturnsNothing3() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing3.kt");
doTest(fileName);
}
@TestMetadata("noSynAccessor.kt")
public void testNoSynAccessor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inline/noSynAccessor.kt");
@@ -2422,6 +2422,45 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ReturnsNothing extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInReturnsNothing() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/returnsNothing"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ifElse.kt")
public void testIfElse() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing/ifElse.kt");
doTest(fileName);
}
@TestMetadata("inlineMethod.kt")
public void testInlineMethod() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing/inlineMethod.kt");
doTest(fileName);
}
@TestMetadata("propertyGetter.kt")
public void testPropertyGetter() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing/propertyGetter.kt");
doTest(fileName);
}
@TestMetadata("tryCatch.kt")
public void testTryCatch() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing/tryCatch.kt");
doTest(fileName);
}
@TestMetadata("when.kt")
public void testWhen() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing/when.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/tryCatchInExpressions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)