Tests for bug in CFA: no return in when() is now detected
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
== illegalWhenBlock ==
|
||||||
|
fun illegalWhenBlock(a: Any): Any {
|
||||||
|
when(a) {
|
||||||
|
is Int -> return a
|
||||||
|
is String -> return a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
L0:
|
||||||
|
<START> NEXT:[v(a: Any)] PREV:[]
|
||||||
|
v(a: Any) NEXT:[w(a)] PREV:[<START>]
|
||||||
|
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:[<END>] PREV:[r(a)]
|
||||||
|
- jmp(L2) NEXT:[<END>] PREV:[]
|
||||||
|
L4:
|
||||||
|
jmp?(L6) NEXT:[<END>, r(a)] PREV:[jmp?(L4)]
|
||||||
|
L5:
|
||||||
|
r(a) NEXT:[ret(*) L1] PREV:[jmp?(L6)]
|
||||||
|
ret(*) L1 NEXT:[<END>] PREV:[r(a)]
|
||||||
|
- jmp(L2) NEXT:[<END>] PREV:[]
|
||||||
|
L1:
|
||||||
|
L2:
|
||||||
|
L6:
|
||||||
|
<END> NEXT:[<SINK>] PREV:[ret(*) L1, jmp?(L6), ret(*) L1]
|
||||||
|
error:
|
||||||
|
<ERROR> NEXT:[<SINK>] PREV:[]
|
||||||
|
sink:
|
||||||
|
<SINK> NEXT:[] PREV:[<ERROR>, <END>]
|
||||||
|
=====================
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun illegalWhenBlock(a: Any): Any {
|
||||||
|
when(a) {
|
||||||
|
is Int -> return a
|
||||||
|
is String -> return a
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun illegalWhenBlock(a: Any): Int {
|
||||||
|
when(a) {
|
||||||
|
is Int -> return a
|
||||||
|
is String -> return a.length
|
||||||
|
}
|
||||||
|
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||||
@@ -150,7 +150,7 @@ fun illegalWhenBlock(a: Any): Int {
|
|||||||
is Int -> return a
|
is Int -> return a
|
||||||
is String -> return <!TYPE_MISMATCH!>a<!>
|
is String -> return <!TYPE_MISMATCH!>a<!>
|
||||||
}
|
}
|
||||||
}
|
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||||
fun declarations(a: Any?) {
|
fun declarations(a: Any?) {
|
||||||
if (a is String) {
|
if (a is String) {
|
||||||
val <!UNUSED_VARIABLE!>p4<!>: String = a
|
val <!UNUSED_VARIABLE!>p4<!>: String = a
|
||||||
|
|||||||
@@ -166,6 +166,11 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest {
|
|||||||
doTest("compiler/testData/cfg/ReturnFromExpression.kt");
|
doTest("compiler/testData/cfg/ReturnFromExpression.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("returnsInWhen.kt")
|
||||||
|
public void testReturnsInWhen() throws Exception {
|
||||||
|
doTest("compiler/testData/cfg/returnsInWhen.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ShortFunction.kt")
|
@TestMetadata("ShortFunction.kt")
|
||||||
public void testShortFunction() throws Exception {
|
public void testShortFunction() throws Exception {
|
||||||
doTest("compiler/testData/cfg/ShortFunction.kt");
|
doTest("compiler/testData/cfg/ShortFunction.kt");
|
||||||
|
|||||||
@@ -1407,6 +1407,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/DeadCode.kt");
|
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")
|
@TestMetadata("kt1001.kt")
|
||||||
public void testKt1001() throws Exception {
|
public void testKt1001() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.kt");
|
doTest("compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1001.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user