Files
Kirill Rakhman 69a7bf7f68 [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
2024-03-05 17:38:59 +00:00

444 lines
17 KiB
Plaintext
Vendored

digraph smartcastToNothing_kt {
graph [nodesep=3]
node [shape=box penwidth=2]
edge [penwidth=2]
subgraph cluster_0 {
color=red
0 [label="Enter file smartcastToNothing.kt" style="filled" fillcolor=red];
1 [label="Exit file smartcastToNothing.kt" style="filled" fillcolor=red];
}
0 -> {1} [color=green];
subgraph cluster_1 {
color=red
2 [label="Enter function getNothing" style="filled" fillcolor=red];
subgraph cluster_2 {
color=blue
3 [label="Enter block"];
subgraph cluster_3 {
color=blue
4 [label="Function call arguments enter"];
5 [label="Function call arguments exit"];
}
6 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow];
7 [label="Throw: throw R|java/lang/Exception.Exception|()"];
8 [label="Stub" style="filled" fillcolor=gray];
9 [label="Jump: ^getNothing throw R|java/lang/Exception.Exception|()" style="filled" fillcolor=gray];
10 [label="Stub" style="filled" fillcolor=gray];
11 [label="Exit block" style="filled" fillcolor=gray];
}
12 [label="Exit function getNothing" style="filled" fillcolor=gray];
}
2 -> {3};
3 -> {4};
4 -> {5};
5 -> {6};
6 -> {7};
7 -> {8} [style=dotted];
8 -> {9} [style=dotted];
9 -> {10 12} [style=dotted];
10 -> {11} [style=dotted];
11 -> {12} [style=dotted];
subgraph cluster_4 {
color=red
13 [label="Enter function getNullableNothing" style="filled" fillcolor=red];
subgraph cluster_5 {
color=blue
14 [label="Enter block"];
15 [label="Const: Null(null)"];
16 [label="Jump: ^getNullableNothing Null(null)"];
17 [label="Stub" style="filled" fillcolor=gray];
18 [label="Exit block" style="filled" fillcolor=gray];
}
19 [label="Exit function getNullableNothing" style="filled" fillcolor=red];
}
13 -> {14};
14 -> {15};
15 -> {16};
16 -> {19};
16 -> {17} [style=dotted];
17 -> {18} [style=dotted];
18 -> {19} [style=dotted];
subgraph cluster_6 {
color=red
20 [label="Enter function <getter>" style="filled" fillcolor=red];
subgraph cluster_7 {
color=blue
21 [label="Enter block"];
22 [label="Const: Int(1)"];
23 [label="Jump: ^ Int(1)"];
24 [label="Stub" style="filled" fillcolor=gray];
25 [label="Exit block" style="filled" fillcolor=gray];
}
26 [label="Exit function <getter>" style="filled" fillcolor=red];
}
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {26};
23 -> {24} [style=dotted];
24 -> {25} [style=dotted];
25 -> {26} [style=dotted];
subgraph cluster_8 {
color=red
27 [label="Enter function <getter>" style="filled" fillcolor=red];
subgraph cluster_9 {
color=blue
28 [label="Enter block"];
29 [label="Const: Int(2)"];
30 [label="Jump: ^ Int(2)"];
31 [label="Stub" style="filled" fillcolor=gray];
32 [label="Exit block" style="filled" fillcolor=gray];
}
33 [label="Exit function <getter>" style="filled" fillcolor=red];
}
27 -> {28};
28 -> {29};
29 -> {30};
30 -> {33};
30 -> {31} [style=dotted];
31 -> {32} [style=dotted];
32 -> {33} [style=dotted];
subgraph cluster_10 {
color=red
34 [label="Enter function myListOf" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
35 [label="Enter block"];
36 [label="Const: Null(null)"];
37 [label="Check not null: Null(null)!!" style="filled" fillcolor=yellow];
38 [label="Jump: ^myListOf Null(null)!!"];
39 [label="Stub" style="filled" fillcolor=gray];
40 [label="Exit block" style="filled" fillcolor=gray];
}
41 [label="Exit function myListOf" style="filled" fillcolor=red];
}
34 -> {35};
35 -> {36};
36 -> {37};
37 -> {38};
38 -> {41};
38 -> {39} [style=dotted];
39 -> {40} [style=dotted];
40 -> {41} [style=dotted];
subgraph cluster_12 {
color=red
42 [label="Enter class A" style="filled" fillcolor=red];
subgraph cluster_13 {
color=blue
43 [label="Enter function <init>" style="filled" fillcolor=red];
44 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
45 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_14 {
color=blue
46 [label="Enter property" style="filled" fillcolor=red];
47 [label="Const: Int(1)"];
48 [label="Exit property" style="filled" fillcolor=red];
}
subgraph cluster_15 {
color=blue
49 [label="Enter property" style="filled" fillcolor=red];
50 [label="Const: Boolean(true)"];
51 [label="Exit property" style="filled" fillcolor=red];
}
52 [label="Exit class A" style="filled" fillcolor=red];
}
42 -> {43} [color=green];
42 -> {52} [style=dotted];
42 -> {43 46 49} [style=dashed];
43 -> {44};
44 -> {45};
45 -> {46} [color=green];
46 -> {47};
47 -> {48};
48 -> {49} [color=green];
49 -> {50};
50 -> {51};
51 -> {52} [color=green];
subgraph cluster_16 {
color=red
53 [label="Enter function test_0" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
54 [label="Enter block"];
55 [label="Const: Null(null)"];
56 [label="Variable declaration: lvar s: R|A?|"];
subgraph cluster_18 {
color=blue
57 [label="Enter block"];
subgraph cluster_19 {
color=blue
58 [label="Function call arguments enter"];
59 [label="Access variable R|<local>/results|"];
60 [label="Function call arguments exit"];
}
61 [label="Function call: R|<local>/results|.R|SubstitutionOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<kotlin/Nothing>|>|()" style="filled" fillcolor=yellow];
62 [label="Variable declaration: lval <iterator>: R|kotlin/collections/Iterator<kotlin/Nothing>|"];
subgraph cluster_20 {
color=blue
63 [label="Enter while loop"];
subgraph cluster_21 {
color=blue
64 [label="Enter loop condition"];
subgraph cluster_22 {
color=blue
65 [label="Function call arguments enter"];
66 [label="Access variable R|<local>/<iterator>|"];
67 [label="Function call arguments exit"];
}
68 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()" style="filled" fillcolor=yellow];
69 [label="Exit loop condition"];
}
subgraph cluster_23 {
color=blue
70 [label="Enter loop block"];
subgraph cluster_24 {
color=blue
71 [label="Enter block"];
subgraph cluster_25 {
color=blue
72 [label="Function call arguments enter"];
73 [label="Access variable R|<local>/<iterator>|"];
74 [label="Function call arguments exit"];
}
75 [label="Function call: R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.next: R|kotlin/Nothing|>|()" style="filled" fillcolor=yellow];
76 [label="Stub" style="filled" fillcolor=gray];
77 [label="Variable declaration: lval result: R|kotlin/Nothing|" style="filled" fillcolor=gray];
subgraph cluster_26 {
color=blue
78 [label="Enter block" style="filled" fillcolor=gray];
79 [label="Access variable R|<local>/result|" style="filled" fillcolor=gray];
80 [label="Stub" style="filled" fillcolor=gray];
81 [label="Assignment: R|<local>/s|" style="filled" fillcolor=gray];
subgraph cluster_27 {
color=blue
82 [label="Enter when" style="filled" fillcolor=gray];
subgraph cluster_28 {
color=blue
83 [label="Enter when branch condition " style="filled" fillcolor=gray];
84 [label="Access variable R|<local>/result|" style="filled" fillcolor=gray];
85 [label="Stub" style="filled" fillcolor=gray];
86 [label="Access variable <Unresolved name: b>#" style="filled" fillcolor=gray];
87 [label="Exit when branch condition" style="filled" fillcolor=gray];
}
88 [label="Synthetic else branch" style="filled" fillcolor=gray];
89 [label="Enter when branch result" style="filled" fillcolor=gray];
subgraph cluster_29 {
color=blue
90 [label="Enter block" style="filled" fillcolor=gray];
91 [label="Jump: break@@@[R|<local>/<iterator>|.R|SubstitutionOverride<kotlin/collections/Iterator.hasNext: R|kotlin/Boolean|>|()] " style="filled" fillcolor=gray];
92 [label="Stub" style="filled" fillcolor=gray];
93 [label="Exit block" style="filled" fillcolor=gray];
}
94 [label="Exit when branch result" style="filled" fillcolor=gray];
95 [label="Exit when" style="filled" fillcolor=gray];
}
96 [label="Exit block" style="filled" fillcolor=gray];
}
97 [label="Exit block" style="filled" fillcolor=gray];
}
98 [label="Exit loop block" style="filled" fillcolor=gray];
}
99 [label="Exit while loop"];
}
100 [label="Exit block"];
}
101 [label="Access variable R|<local>/s|"];
102 [label="Enter safe call"];
subgraph cluster_30 {
color=blue
103 [label="Function call arguments enter"];
104 [label="Postponed enter to lambda"];
subgraph cluster_31 {
color=blue
105 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_32 {
color=blue
106 [label="Enter block"];
107 [label="Access variable R|<local>/it|"];
108 [label="Access variable R|/A.a|"];
109 [label="Exit block"];
}
110 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
111 [label="Function call arguments exit"];
}
112 [label="Postponed exit from lambda"];
113 [label="Function call: $subj$.R|kotlin/let|<R|A|, R|kotlin/Int|>(...)" style="filled" fillcolor=yellow];
114 [label="Exit safe call"];
115 [label="Exit block"];
}
116 [label="Exit function test_0" style="filled" fillcolor=red];
}
53 -> {54};
54 -> {55};
55 -> {56};
56 -> {57};
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {63};
63 -> {64};
64 -> {65};
65 -> {66};
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70 99};
70 -> {71};
71 -> {72};
72 -> {73};
73 -> {74};
74 -> {75};
75 -> {76} [style=dotted];
76 -> {77} [style=dotted];
77 -> {78} [style=dotted];
78 -> {79} [style=dotted];
79 -> {80} [style=dotted];
80 -> {81} [style=dotted];
81 -> {82} [style=dotted];
82 -> {83} [style=dotted];
83 -> {84} [style=dotted];
84 -> {85} [style=dotted];
85 -> {86} [style=dotted];
86 -> {87} [style=dotted];
87 -> {88 89} [style=dotted];
88 -> {95} [style=dotted];
89 -> {90} [style=dotted];
90 -> {91} [style=dotted];
91 -> {92 99} [style=dotted];
92 -> {93} [style=dotted];
93 -> {94} [style=dotted];
94 -> {95} [style=dotted];
95 -> {96} [style=dotted];
96 -> {97} [style=dotted];
97 -> {98} [style=dotted];
98 -> {64} [color=green style=dotted];
99 -> {100};
100 -> {101};
101 -> {102 114};
102 -> {103};
103 -> {104};
104 -> {105 111};
104 -> {112} [style=dotted];
104 -> {105} [style=dashed];
105 -> {106};
106 -> {107};
107 -> {108};
108 -> {109};
109 -> {110};
110 -> {112};
111 -> {113};
112 -> {113} [label="Postponed"];
113 -> {114};
114 -> {115};
115 -> {116};
subgraph cluster_33 {
color=red
117 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_34 {
color=blue
118 [label="Enter block"];
subgraph cluster_35 {
color=blue
119 [label="Enter when"];
subgraph cluster_36 {
color=blue
120 [label="Enter when branch condition "];
121 [label="Access variable R|<local>/a|"];
122 [label="Type operator: (R|<local>/a| is R|kotlin/Nothing?|)"];
123 [label="Exit when branch condition"];
}
124 [label="Synthetic else branch"];
125 [label="Enter when branch result"];
subgraph cluster_37 {
color=blue
126 [label="Enter block"];
127 [label="Access variable R|<local>/a|"];
128 [label="Smart cast: R|<local>/a|"];
129 [label="Enter safe call"];
130 [label="Access variable R|kotlin/String.length|"];
131 [label="Exit safe call"];
132 [label="Variable declaration: lval b: R|kotlin/Int?|"];
133 [label="Exit block"];
}
134 [label="Exit when branch result"];
135 [label="Exit when"];
}
subgraph cluster_38 {
color=blue
136 [label="Enter when"];
subgraph cluster_39 {
color=blue
137 [label="Enter when branch condition "];
138 [label="Access variable R|<local>/a|"];
139 [label="Type operator: (R|<local>/a| is R|kotlin/Nothing|)"];
140 [label="Exit when branch condition"];
}
141 [label="Synthetic else branch"];
142 [label="Enter when branch result"];
subgraph cluster_40 {
color=blue
143 [label="Enter block"];
144 [label="Access variable R|<local>/a|"];
145 [label="Smart cast: R|<local>/a|"];
146 [label="Access variable R|kotlin/String.length|"];
147 [label="Variable declaration: lval b: R|kotlin/Int|"];
148 [label="Exit block"];
}
149 [label="Exit when branch result"];
150 [label="Exit when"];
}
151 [label="Exit block"];
}
152 [label="Exit function test_1" style="filled" fillcolor=red];
}
117 -> {118};
118 -> {119};
119 -> {120};
120 -> {121};
121 -> {122};
122 -> {123};
123 -> {124 125};
124 -> {135};
125 -> {126};
126 -> {127};
127 -> {128};
128 -> {129 131};
129 -> {130};
130 -> {131};
131 -> {132};
132 -> {133};
133 -> {134};
134 -> {135};
135 -> {136};
136 -> {137};
137 -> {138};
138 -> {139};
139 -> {140};
140 -> {141 142};
141 -> {150};
142 -> {143};
143 -> {144};
144 -> {145};
145 -> {146};
146 -> {147};
147 -> {148};
148 -> {149};
149 -> {150};
150 -> {151};
151 -> {152};
}