[FIR] Add equality constraint from expected type for some synthetic function calls

This fixes some cases where we infer some type variable inside one
of the branches to Nothing instead of the expected type because Nothing
appeared in some other branch.

Specifically, we add an equality instead of a subtype constraint during
completion of calls to synthetic functions for if/when, try and !!.
We don't do it when the call contains a (possibly nested) elvis or is
inside the RHS of an assignment.
Otherwise, we would prevent some smart-casts.

#KT-65882 Fixed
This commit is contained in:
Kirill Rakhman
2024-02-21 16:06:47 +01:00
committed by Space Team
parent eaef7122f6
commit 69a7bf7f68
106 changed files with 1441 additions and 578 deletions
@@ -18,154 +18,153 @@ digraph plusAssignWithLambdaInRhs_kt {
3 [label="Enter block"];
4 [label="Const: Null(null)"];
5 [label="Check not null: Null(null)!!" style="filled" fillcolor=yellow];
6 [label="Stub" style="filled" fillcolor=gray];
7 [label="Variable declaration: lval list: R|kotlin/collections/MutableList<kotlin/Function1<kotlin/String, kotlin/String>>|" style="filled" fillcolor=gray];
8 [label="Access variable R|<local>/list|" style="filled" fillcolor=gray];
9 [label="Postponed enter to lambda" style="filled" fillcolor=gray];
6 [label="Variable declaration: lval list: R|kotlin/collections/MutableList<kotlin/Function1<kotlin/String, kotlin/String>>|"];
7 [label="Access variable R|<local>/list|"];
8 [label="Postponed enter to lambda"];
subgraph cluster_3 {
color=blue
10 [label="Enter function <anonymous>" style="filled" fillcolor=gray];
9 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_4 {
color=blue
11 [label="Enter block" style="filled" fillcolor=gray];
12 [label="Access variable R|<local>/it|" style="filled" fillcolor=gray];
13 [label="Exit block" style="filled" fillcolor=gray];
10 [label="Enter block"];
11 [label="Access variable R|<local>/it|"];
12 [label="Exit block"];
}
14 [label="Exit function <anonymous>" style="filled" fillcolor=gray];
13 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
15 [label="Postponed exit from lambda" style="filled" fillcolor=gray];
16 [label="Function call: R|<local>/list|.R|kotlin/collections/plusAssign|<R|(kotlin/String) -> kotlin/String|>(...)" style="filled" fillcolor=gray];
17 [label="Exit block" style="filled" fillcolor=gray];
14 [label="Postponed exit from lambda"];
15 [label="Function call: R|<local>/list|.R|kotlin/collections/plusAssign|<R|(kotlin/String) -> kotlin/String|>(...)" style="filled" fillcolor=yellow];
16 [label="Exit block"];
}
18 [label="Exit function test" style="filled" fillcolor=gray];
17 [label="Exit function test" style="filled" fillcolor=red];
}
2 -> {3};
3 -> {4};
4 -> {5};
5 -> {6} [style=dotted];
6 -> {7} [style=dotted];
7 -> {8} [style=dotted];
8 -> {9} [style=dotted];
9 -> {10 15 16} [style=dotted];
9 -> {10} [style=dashed];
10 -> {11} [style=dotted];
11 -> {12} [style=dotted];
12 -> {13} [style=dotted];
13 -> {14} [style=dotted];
15 -> {16} [style=dotted label="Postponed"];
16 -> {17} [style=dotted];
17 -> {18} [style=dotted];
5 -> {6};
6 -> {7};
7 -> {8};
8 -> {9 14 15};
8 -> {9} [style=dashed];
9 -> {10};
10 -> {11};
11 -> {12};
12 -> {13};
14 -> {15} [label="Postponed"];
15 -> {16};
16 -> {17};
subgraph cluster_5 {
color=red
19 [label="Enter class A" style="filled" fillcolor=red];
18 [label="Enter class A" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
20 [label="Enter function <init>" style="filled" fillcolor=red];
21 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
22 [label="Exit function <init>" style="filled" fillcolor=red];
19 [label="Enter function <init>" style="filled" fillcolor=red];
20 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
21 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_7 {
color=blue
23 [label="Enter property" style="filled" fillcolor=red];
24 [label="Access variable R|<local>/executor|"];
25 [label="Exit property" style="filled" fillcolor=red];
22 [label="Enter property" style="filled" fillcolor=red];
23 [label="Access variable R|<local>/executor|"];
24 [label="Exit property" style="filled" fillcolor=red];
}
26 [label="Exit class A" style="filled" fillcolor=red];
25 [label="Exit class A" style="filled" fillcolor=red];
}
19 -> {20} [color=green];
19 -> {26} [style=dotted];
19 -> {20 23} [style=dashed];
18 -> {19} [color=green];
18 -> {25} [style=dotted];
18 -> {19 22} [style=dashed];
19 -> {20};
20 -> {21};
21 -> {22};
22 -> {23} [color=green];
21 -> {22} [color=green];
22 -> {23};
23 -> {24};
24 -> {25};
25 -> {26} [color=green];
24 -> {25} [color=green];
subgraph cluster_8 {
color=red
27 [label="Enter function postpone" style="filled" fillcolor=red];
26 [label="Enter function postpone" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
28 [label="Enter block"];
27 [label="Enter block"];
subgraph cluster_10 {
color=blue
29 [label="Function call arguments enter"];
30 [label="Function call arguments exit"];
28 [label="Function call arguments enter"];
29 [label="Function call arguments exit"];
}
31 [label="Function call: R|kotlin/collections/mutableListOf|<R|() -> kotlin/Unit|>()" style="filled" fillcolor=yellow];
32 [label="Variable declaration: lval queue: R|kotlin/collections/MutableList<kotlin/Function0<kotlin/Unit>>|"];
30 [label="Function call: R|kotlin/collections/mutableListOf|<R|() -> kotlin/Unit|>()" style="filled" fillcolor=yellow];
31 [label="Variable declaration: lval queue: R|kotlin/collections/MutableList<kotlin/Function0<kotlin/Unit>>|"];
subgraph cluster_11 {
color=blue
33 [label="Function call arguments enter"];
34 [label="Postponed enter to lambda"];
32 [label="Function call arguments enter"];
33 [label="Postponed enter to lambda"];
subgraph cluster_12 {
color=blue
35 [label="Enter function <anonymous>" style="filled" fillcolor=red];
34 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
36 [label="Enter block"];
37 [label="Access variable R|<local>/queue|"];
38 [label="Postponed enter to lambda"];
35 [label="Enter block"];
36 [label="Access variable R|<local>/queue|"];
37 [label="Postponed enter to lambda"];
subgraph cluster_14 {
color=blue
39 [label="Enter function <anonymous>" style="filled" fillcolor=red];
38 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_15 {
color=blue
40 [label="Enter block"];
39 [label="Enter block"];
subgraph cluster_16 {
color=blue
41 [label="Function call arguments enter"];
40 [label="Function call arguments enter"];
subgraph cluster_17 {
color=blue
42 [label="Function call arguments enter"];
43 [label="Function call arguments exit"];
41 [label="Function call arguments enter"];
42 [label="Function call arguments exit"];
}
44 [label="Function call: R|<local>/computation|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()" style="filled" fillcolor=yellow];
45 [label="Function call arguments exit"];
43 [label="Function call: R|<local>/computation|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|()" style="filled" fillcolor=yellow];
44 [label="Function call arguments exit"];
}
46 [label="Function call: R|<local>/resolve|.R|SubstitutionOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(...)" style="filled" fillcolor=yellow];
47 [label="Exit block"];
45 [label="Function call: R|<local>/resolve|.R|SubstitutionOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(...)" style="filled" fillcolor=yellow];
46 [label="Exit block"];
}
48 [label="Exit function <anonymous>" style="filled" fillcolor=red];
47 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
49 [label="Postponed exit from lambda"];
50 [label="Function call: R|<local>/queue|.R|kotlin/collections/plusAssign|<R|() -> kotlin/Unit|>(...)" style="filled" fillcolor=yellow];
51 [label="Exit block"];
48 [label="Postponed exit from lambda"];
49 [label="Function call: R|<local>/queue|.R|kotlin/collections/plusAssign|<R|() -> kotlin/Unit|>(...)" style="filled" fillcolor=yellow];
50 [label="Exit block"];
}
52 [label="Exit function <anonymous>" style="filled" fillcolor=red];
51 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
53 [label="Function call arguments exit"];
52 [label="Function call arguments exit"];
}
54 [label="Postponed exit from lambda"];
55 [label="Function call: R|/A.A|<R|T|>(...)" style="filled" fillcolor=yellow];
56 [label="Jump: ^postpone R|/A.A|<R|T|>(<L> = A@fun <anonymous>(resolve: R|(T) -> kotlin/Unit|): R|kotlin/Unit| <inline=NoInline> {
53 [label="Postponed exit from lambda"];
54 [label="Function call: R|/A.A|<R|T|>(...)" style="filled" fillcolor=yellow];
55 [label="Jump: ^postpone R|/A.A|<R|T|>(<L> = A@fun <anonymous>(resolve: R|(T) -> kotlin/Unit|): R|kotlin/Unit| <inline=NoInline> {
R|<local>/queue|.R|kotlin/collections/plusAssign|<R|() -> kotlin/Unit|>(fun <anonymous>(): R|kotlin/Unit| <inline=NoInline> {
R|<local>/resolve|.R|SubstitutionOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(R|<local>/computation|.R|SubstitutionOverride<kotlin/Function0.invoke: R|T|>|())
}
)
}
)"];
57 [label="Stub" style="filled" fillcolor=gray];
58 [label="Exit block" style="filled" fillcolor=gray];
56 [label="Stub" style="filled" fillcolor=gray];
57 [label="Exit block" style="filled" fillcolor=gray];
}
59 [label="Exit function postpone" style="filled" fillcolor=red];
58 [label="Exit function postpone" style="filled" fillcolor=red];
}
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {31};
31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35 53 54};
34 -> {35} [style=dashed];
33 -> {34 52 53};
33 -> {34} [style=dashed];
34 -> {35};
35 -> {36};
36 -> {37};
37 -> {38};
38 -> {39 49 50};
38 -> {39} [style=dashed];
37 -> {38 48 49};
37 -> {38} [style=dashed];
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
@@ -174,16 +173,15 @@ digraph plusAssignWithLambdaInRhs_kt {
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {48};
49 -> {50} [label="Postponed"];
48 -> {49} [label="Postponed"];
49 -> {50};
50 -> {51};
51 -> {52};
53 -> {55};
54 -> {55} [label="Postponed"];
55 -> {56};
56 -> {59};
52 -> {54};
53 -> {54} [label="Postponed"];
54 -> {55};
55 -> {58};
55 -> {56} [style=dotted];
56 -> {57} [style=dotted];
57 -> {58} [style=dotted];
58 -> {59} [style=dotted];
}