[FIR] Add test for smartcast with return in elvis
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
digraph elvis_kt {
|
||||
subgraph foo {
|
||||
0 [shape=box label="Enter function foo"];
|
||||
1 [shape=box label="Exit function foo"];
|
||||
|
||||
0 -> {1};
|
||||
}
|
||||
|
||||
subgraph val_b {
|
||||
2 [shape=box label="Enter property"];
|
||||
3 [shape=box label="Exit property"];
|
||||
|
||||
2 -> {3};
|
||||
}
|
||||
|
||||
subgraph test_1 {
|
||||
4 [shape=box label="Enter function test_1"];
|
||||
5 [shape=box label="Enter block"];
|
||||
6 [shape=box label="Enter when"];
|
||||
7 [shape=box label="Enter when branch condition "];
|
||||
8 [shape=box label="Enter when"];
|
||||
9 [shape=box label="Access variable R|<local>/x|"];
|
||||
10 [shape=box label="Access variable R|/A.b|"];
|
||||
11 [shape=box label="Variable declaration: lval <elvis>: R|kotlin/Boolean?|"];
|
||||
12 [shape=box label="Enter when branch condition "];
|
||||
13 [shape=box label="Const: Null(null)"];
|
||||
14 [shape=box label="Operator =="];
|
||||
15 [shape=box label="Exit when branch condition"];
|
||||
16 [shape=box label="Enter block"];
|
||||
17 [shape=box label="Jump: ^test_1 Unit"];
|
||||
18 [shape=box label="Stub[DEAD]"];
|
||||
19 [shape=box label="Exit block[DEAD]"];
|
||||
20 [shape=box label="Exit when branch result[DEAD]"];
|
||||
21 [shape=box label="Enter when branch condition else"];
|
||||
22 [shape=box label="Exit when branch condition"];
|
||||
23 [shape=box label="Enter block"];
|
||||
24 [shape=box label="Access variable R|<local>/<elvis>|"];
|
||||
25 [shape=box label="Exit block"];
|
||||
26 [shape=box label="Exit when branch result"];
|
||||
27 [shape=box label="Exit when"];
|
||||
28 [shape=box label="Exit when branch condition"];
|
||||
29 [shape=box label="Enter block"];
|
||||
30 [shape=box label="Access variable R|<local>/x|"];
|
||||
31 [shape=box label="Function call: R|<local>/x|.R|/A.foo|()"];
|
||||
32 [shape=box label="Exit block"];
|
||||
33 [shape=box label="Exit when branch result"];
|
||||
34 [shape=box label="Enter when branch condition else"];
|
||||
35 [shape=box label="Exit when branch condition"];
|
||||
36 [shape=box label="Enter block"];
|
||||
37 [shape=box label="Exit block"];
|
||||
38 [shape=box label="Exit when branch result"];
|
||||
39 [shape=box label="Exit when"];
|
||||
40 [shape=box label="Exit block"];
|
||||
41 [shape=box label="Exit function test_1"];
|
||||
|
||||
4 -> {5};
|
||||
5 -> {6};
|
||||
6 -> {7};
|
||||
7 -> {8};
|
||||
8 -> {9};
|
||||
9 -> {10};
|
||||
10 -> {11};
|
||||
11 -> {12};
|
||||
12 -> {13};
|
||||
13 -> {14};
|
||||
14 -> {15};
|
||||
15 -> {16 21};
|
||||
16 -> {17};
|
||||
17 -> {41};
|
||||
17 -> {18} [style=dotted];
|
||||
18 -> {19} [style=dotted];
|
||||
19 -> {20} [style=dotted];
|
||||
20 -> {27} [style=dotted];
|
||||
21 -> {22};
|
||||
22 -> {23};
|
||||
23 -> {24};
|
||||
24 -> {25};
|
||||
25 -> {26};
|
||||
26 -> {27};
|
||||
27 -> {28};
|
||||
28 -> {29 34};
|
||||
29 -> {30};
|
||||
30 -> {31};
|
||||
31 -> {32};
|
||||
32 -> {33};
|
||||
33 -> {39};
|
||||
34 -> {35};
|
||||
35 -> {36};
|
||||
36 -> {37};
|
||||
37 -> {38};
|
||||
38 -> {39};
|
||||
39 -> {40};
|
||||
40 -> {41};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
interface A {
|
||||
fun foo()
|
||||
val b: Boolean
|
||||
}
|
||||
|
||||
fun test_1(x: A?) {
|
||||
if (x?.b ?: return) {
|
||||
x.foo()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
FILE: elvis.kt
|
||||
public abstract interface A : R|kotlin/Any| {
|
||||
public abstract fun foo(): R|kotlin/Unit|
|
||||
|
||||
public abstract val b: R|kotlin/Boolean|
|
||||
public get(): R|kotlin/Boolean|
|
||||
|
||||
}
|
||||
public final fun test_1(x: R|A?|): R|kotlin/Unit| {
|
||||
when () {
|
||||
when (lval <elvis>: R|kotlin/Boolean?| = R|<local>/x|?.R|/A.b|) {
|
||||
==($subj$, Null(null)) -> {
|
||||
^test_1 Unit
|
||||
}
|
||||
else -> {
|
||||
R|<local>/<elvis>|!
|
||||
}
|
||||
}
|
||||
-> {
|
||||
R|<local>/x|.R|/A.foo|()
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -109,6 +109,11 @@ public class FirCfgBuildingTestGenerated extends AbstractFirCfgBuildingTest {
|
||||
runTest("compiler/fir/resolve/testData/resolve/smartcasts/casts.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("elvis.kt")
|
||||
public void testElvis() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/smartcasts/elvis.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("equalsAndIdentity.kt")
|
||||
public void testEqualsAndIdentity() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/smartcasts/equalsAndIdentity.kt");
|
||||
|
||||
Reference in New Issue
Block a user