diff --git a/compiler/testData/cfg/returnsInWhen.instructions b/compiler/testData/cfg/returnsInWhen.instructions new file mode 100644 index 00000000000..1322b234778 --- /dev/null +++ b/compiler/testData/cfg/returnsInWhen.instructions @@ -0,0 +1,33 @@ +== illegalWhenBlock == +fun illegalWhenBlock(a: Any): Any { + when(a) { + is Int -> return a + is String -> return a + } +} +--------------------- +L0: + NEXT:[v(a: Any)] PREV:[] + v(a: Any) NEXT:[w(a)] PREV:[] + w(a) NEXT:[r(a)] PREV:[v(a: Any)] + r(a) NEXT:[jmp?(L4)] PREV:[w(a)] + jmp?(L4) NEXT:[jmp?(L6), r(a)] PREV:[r(a)] +L3: + r(a) NEXT:[ret(*) L1] PREV:[jmp?(L4)] + ret(*) L1 NEXT:[] PREV:[r(a)] +- jmp(L2) NEXT:[] PREV:[] +L4: + jmp?(L6) NEXT:[, r(a)] PREV:[jmp?(L4)] +L5: + r(a) NEXT:[ret(*) L1] PREV:[jmp?(L6)] + ret(*) L1 NEXT:[] PREV:[r(a)] +- jmp(L2) NEXT:[] PREV:[] +L1: +L2: +L6: + NEXT:[] PREV:[ret(*) L1, jmp?(L6), ret(*) L1] +error: + NEXT:[] PREV:[] +sink: + NEXT:[] PREV:[, ] +===================== diff --git a/compiler/testData/cfg/returnsInWhen.kt b/compiler/testData/cfg/returnsInWhen.kt new file mode 100644 index 00000000000..e224245ffe6 --- /dev/null +++ b/compiler/testData/cfg/returnsInWhen.kt @@ -0,0 +1,6 @@ +fun illegalWhenBlock(a: Any): Any { + when(a) { + is Int -> return a + is String -> return a + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.kt new file mode 100644 index 00000000000..947fa170e11 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.kt @@ -0,0 +1,6 @@ +fun illegalWhenBlock(a: Any): Int { + when(a) { + is Int -> return a + is String -> return a.length + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/infos/Autocasts.kt b/compiler/testData/diagnostics/tests/infos/Autocasts.kt index 3654b6415e2..dbc70c7e176 100644 --- a/compiler/testData/diagnostics/tests/infos/Autocasts.kt +++ b/compiler/testData/diagnostics/tests/infos/Autocasts.kt @@ -150,7 +150,7 @@ fun illegalWhenBlock(a: Any): Int { is Int -> return a is String -> return a } -} +} fun declarations(a: Any?) { if (a is String) { val p4: String = a diff --git a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java index 7d536615b21..3c56963bcd2 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java @@ -166,6 +166,11 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest { doTest("compiler/testData/cfg/ReturnFromExpression.kt"); } + @TestMetadata("returnsInWhen.kt") + public void testReturnsInWhen() throws Exception { + doTest("compiler/testData/cfg/returnsInWhen.kt"); + } + @TestMetadata("ShortFunction.kt") public void testShortFunction() throws Exception { doTest("compiler/testData/cfg/ShortFunction.kt"); diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index e6374cb3d94..68f756abd05 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -1407,6 +1407,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/DeadCode.kt"); } + @TestMetadata("definiteReturnInWhen.kt") + public void testDefiniteReturnInWhen() throws Exception { + doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/definiteReturnInWhen.kt"); + } + @TestMetadata("kt1001.kt") public void testKt1001() throws Exception { doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.kt");