[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
@@ -36,178 +36,178 @@ digraph delegateWithAnonymousObject_kt {
8 [label="Enter block"];
9 [label="Const: Null(null)"];
10 [label="Check not null: Null(null)!!" style="filled" fillcolor=yellow];
11 [label="Stub" style="filled" fillcolor=gray];
12 [label="Jump: ^delegate Null(null)!!" style="filled" fillcolor=gray];
13 [label="Stub" style="filled" fillcolor=gray];
14 [label="Exit block" style="filled" fillcolor=gray];
11 [label="Jump: ^delegate Null(null)!!"];
12 [label="Stub" style="filled" fillcolor=gray];
13 [label="Exit block" style="filled" fillcolor=gray];
}
15 [label="Exit function delegate" style="filled" fillcolor=gray];
14 [label="Exit function delegate" style="filled" fillcolor=red];
}
7 -> {8};
8 -> {9};
9 -> {10};
10 -> {11} [style=dotted];
10 -> {11};
11 -> {14};
11 -> {12} [style=dotted];
12 -> {13 15} [style=dotted];
12 -> {13} [style=dotted];
13 -> {14} [style=dotted];
14 -> {15} [style=dotted];
subgraph cluster_5 {
color=red
16 [label="Enter class IssueListView" style="filled" fillcolor=red];
15 [label="Enter class IssueListView" style="filled" fillcolor=red];
subgraph cluster_6 {
color=blue
17 [label="Enter function <init>" style="filled" fillcolor=red];
18 [label="Delegated constructor call: super<R|DelegateProvider<IssueListView>|>()" style="filled" fillcolor=yellow];
19 [label="Exit function <init>" style="filled" fillcolor=red];
16 [label="Enter function <init>" style="filled" fillcolor=red];
17 [label="Delegated constructor call: super<R|DelegateProvider<IssueListView>|>()" style="filled" fillcolor=yellow];
18 [label="Exit function <init>" style="filled" fillcolor=red];
}
20 [label="Exit class IssueListView" style="filled" fillcolor=red];
19 [label="Exit class IssueListView" style="filled" fillcolor=red];
}
16 -> {17} [color=green];
16 -> {20} [style=dotted];
16 -> {17} [style=dashed];
15 -> {16} [color=green];
15 -> {19} [style=dotted];
15 -> {16} [style=dashed];
16 -> {17};
17 -> {18};
18 -> {19};
19 -> {20} [color=green];
18 -> {19} [color=green];
subgraph cluster_7 {
color=red
21 [label="Enter function updateFrom" style="filled" fillcolor=red];
20 [label="Enter function updateFrom" style="filled" fillcolor=red];
subgraph cluster_8 {
color=blue
22 [label="Enter block"];
23 [label="Exit block"];
21 [label="Enter block"];
22 [label="Exit block"];
}
24 [label="Exit function updateFrom" style="filled" fillcolor=red];
23 [label="Exit function updateFrom" style="filled" fillcolor=red];
}
20 -> {21};
21 -> {22};
22 -> {23};
23 -> {24};
subgraph cluster_9 {
color=red
25 [label="Enter class IssuesListUserProfile" style="filled" fillcolor=red];
24 [label="Enter class IssuesListUserProfile" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
26 [label="Enter function <init>" style="filled" fillcolor=red];
27 [label="Delegated constructor call: super<R|DelegateProvider<IssuesListUserProfile>|>()" style="filled" fillcolor=yellow];
28 [label="Exit function <init>" style="filled" fillcolor=red];
25 [label="Enter function <init>" style="filled" fillcolor=red];
26 [label="Delegated constructor call: super<R|DelegateProvider<IssuesListUserProfile>|>()" style="filled" fillcolor=yellow];
27 [label="Exit function <init>" style="filled" fillcolor=red];
}
subgraph cluster_11 {
color=blue
29 [label="Enter property" style="filled" fillcolor=red];
28 [label="Enter property" style="filled" fillcolor=red];
subgraph cluster_12 {
color=blue
30 [label="Function call arguments enter"];
31 [label="Postponed enter to lambda"];
29 [label="Function call arguments enter"];
30 [label="Postponed enter to lambda"];
subgraph cluster_13 {
color=blue
32 [label="Enter function <anonymous>" style="filled" fillcolor=red];
31 [label="Enter function <anonymous>" style="filled" fillcolor=red];
subgraph cluster_14 {
color=blue
33 [label="Enter block"];
34 [label="Enter anonymous object"];
32 [label="Enter block"];
33 [label="Enter anonymous object"];
subgraph cluster_15 {
color=blue
35 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
34 [label="Enter class <anonymous object>" style="filled" fillcolor=red];
subgraph cluster_16 {
color=blue
36 [label="Enter function <init>" style="filled" fillcolor=red];
37 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
38 [label="Exit function <init>" style="filled" fillcolor=red];
35 [label="Enter function <init>" style="filled" fillcolor=red];
36 [label="Delegated constructor call: super<R|kotlin/Any|>()" style="filled" fillcolor=yellow];
37 [label="Exit function <init>" style="filled" fillcolor=red];
}
39 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
38 [label="Exit class <anonymous object>" style="filled" fillcolor=red];
}
40 [label="Exit anonymous object expression"];
41 [label="Exit block"];
39 [label="Exit anonymous object expression"];
40 [label="Exit block"];
}
42 [label="Exit function <anonymous>" style="filled" fillcolor=red];
41 [label="Exit function <anonymous>" style="filled" fillcolor=red];
}
subgraph cluster_17 {
color=blue
43 [label="Enter function setValue" style="filled" fillcolor=red];
42 [label="Enter function setValue" style="filled" fillcolor=red];
subgraph cluster_18 {
color=blue
44 [label="Enter block"];
43 [label="Enter block"];
subgraph cluster_19 {
color=blue
45 [label="Function call arguments enter"];
44 [label="Function call arguments enter"];
subgraph cluster_20 {
color=blue
46 [label="Function call arguments enter"];
47 [label="Function call arguments exit"];
45 [label="Function call arguments enter"];
46 [label="Function call arguments exit"];
}
48 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
49 [label="Access variable R|<local>/value|"];
50 [label="Function call arguments exit"];
47 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
48 [label="Access variable R|<local>/value|"];
49 [label="Function call arguments exit"];
}
51 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow];
52 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|<local>/value|)"];
53 [label="Stub" style="filled" fillcolor=gray];
54 [label="Exit block" style="filled" fillcolor=gray];
50 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow];
51 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|<local>/value|)"];
52 [label="Stub" style="filled" fillcolor=gray];
53 [label="Exit block" style="filled" fillcolor=gray];
}
55 [label="Exit function setValue" style="filled" fillcolor=red];
54 [label="Exit function setValue" style="filled" fillcolor=red];
}
subgraph cluster_21 {
color=blue
56 [label="Enter function getValue" style="filled" fillcolor=red];
55 [label="Enter function getValue" style="filled" fillcolor=red];
subgraph cluster_22 {
color=blue
57 [label="Enter block"];
56 [label="Enter block"];
subgraph cluster_23 {
color=blue
58 [label="Function call arguments enter"];
59 [label="Function call arguments exit"];
57 [label="Function call arguments enter"];
58 [label="Function call arguments exit"];
}
60 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
61 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"];
62 [label="Stub" style="filled" fillcolor=gray];
63 [label="Exit block" style="filled" fillcolor=gray];
59 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow];
60 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"];
61 [label="Stub" style="filled" fillcolor=gray];
62 [label="Exit block" style="filled" fillcolor=gray];
}
64 [label="Exit function getValue" style="filled" fillcolor=red];
63 [label="Exit function getValue" style="filled" fillcolor=red];
}
65 [label="Function call arguments exit"];
64 [label="Function call arguments exit"];
}
66 [label="Postponed exit from lambda"];
67 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...)" style="filled" fillcolor=yellow];
65 [label="Postponed exit from lambda"];
66 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...)" style="filled" fillcolor=yellow];
subgraph cluster_24 {
color=blue
68 [label="Function call arguments enter"];
69 [label="Function call arguments exit"];
67 [label="Function call arguments enter"];
68 [label="Function call arguments exit"];
}
70 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...).R?C|special/error|(...)" style="filled" fillcolor=yellow];
71 [label="Exit property delegate" style="filled" fillcolor=yellow];
72 [label="Exit property" style="filled" fillcolor=red];
69 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|<R|IssuesListUserProfile|, R|IssuesListUserProfile|, R|IssueListView|>(...).R?C|special/error|(...)" style="filled" fillcolor=yellow];
70 [label="Exit property delegate" style="filled" fillcolor=yellow];
71 [label="Exit property" style="filled" fillcolor=red];
}
73 [label="Exit class IssuesListUserProfile" style="filled" fillcolor=red];
72 [label="Exit class IssuesListUserProfile" style="filled" fillcolor=red];
}
25 -> {26} [color=green];
25 -> {73} [style=dotted];
25 -> {26 29} [style=dashed];
24 -> {25} [color=green];
24 -> {72} [style=dotted];
24 -> {25 28} [style=dashed];
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29} [color=green];
27 -> {28} [color=green];
28 -> {29};
29 -> {30};
30 -> {31};
31 -> {32 65 66};
31 -> {32} [style=dashed];
30 -> {31 64 65};
30 -> {31} [style=dashed];
31 -> {32};
32 -> {33};
33 -> {34};
33 -> {39} [style=dotted];
33 -> {34} [style=dashed];
34 -> {35};
34 -> {40} [style=dotted];
34 -> {42 55} [color=red];
34 -> {38} [style=dotted];
34 -> {35} [style=dashed];
35 -> {36};
35 -> {43 56} [color=red];
35 -> {39} [style=dotted];
35 -> {36} [style=dashed];
36 -> {37};
37 -> {38};
38 -> {39};
38 -> {42 55} [color=green];
38 -> {42 55} [style=dashed];
39 -> {40};
39 -> {43 56} [color=green];
39 -> {43 56} [style=dashed];
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45};
45 -> {46};
@@ -216,90 +216,89 @@ digraph delegateWithAnonymousObject_kt {
48 -> {49};
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {55};
51 -> {54};
51 -> {52} [style=dotted];
52 -> {53} [style=dotted];
53 -> {54} [style=dotted];
54 -> {55} [style=dotted];
55 -> {56};
56 -> {57};
57 -> {58};
58 -> {59};
59 -> {60};
60 -> {61};
61 -> {64};
60 -> {63};
60 -> {61} [style=dotted];
61 -> {62} [style=dotted];
62 -> {63} [style=dotted];
63 -> {64} [style=dotted];
65 -> {67};
66 -> {67} [color=green];
66 -> {71} [color=red label="Postponed"];
64 -> {66};
65 -> {66} [color=green];
65 -> {70} [color=red label="Postponed"];
66 -> {67};
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
72 -> {73} [color=green];
71 -> {72} [color=green];
subgraph cluster_25 {
color=red
74 [label="Enter function <getter>" style="filled" fillcolor=red];
73 [label="Enter function <getter>" style="filled" fillcolor=red];
subgraph cluster_26 {
color=blue
75 [label="Enter block"];
74 [label="Enter block"];
subgraph cluster_27 {
color=blue
76 [label="Function call arguments enter"];
77 [label="Access variable D|/IssuesListUserProfile.issueListView|"];
78 [label="Function call arguments exit"];
75 [label="Function call arguments enter"];
76 [label="Access variable D|/IssuesListUserProfile.issueListView|"];
77 [label="Function call arguments exit"];
}
79 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.getValue: R|IssueListView|>|(...)" style="filled" fillcolor=yellow];
80 [label="Jump: ^ this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.getValue: R|IssueListView|>|(this@R|/IssuesListUserProfile|, ::R|/IssuesListUserProfile.issueListView|)"];
81 [label="Stub" style="filled" fillcolor=gray];
82 [label="Exit block" style="filled" fillcolor=gray];
78 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.getValue: R|IssueListView|>|(...)" style="filled" fillcolor=yellow];
79 [label="Jump: ^ this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.getValue: R|IssueListView|>|(this@R|/IssuesListUserProfile|, ::R|/IssuesListUserProfile.issueListView|)"];
80 [label="Stub" style="filled" fillcolor=gray];
81 [label="Exit block" style="filled" fillcolor=gray];
}
83 [label="Exit function <getter>" style="filled" fillcolor=red];
82 [label="Exit function <getter>" style="filled" fillcolor=red];
}
73 -> {74};
74 -> {75};
75 -> {76};
76 -> {77};
77 -> {78};
78 -> {79};
79 -> {80};
80 -> {83};
79 -> {82};
79 -> {80} [style=dotted];
80 -> {81} [style=dotted];
81 -> {82} [style=dotted];
82 -> {83} [style=dotted];
subgraph cluster_28 {
color=red
84 [label="Enter function <setter>" style="filled" fillcolor=red];
83 [label="Enter function <setter>" style="filled" fillcolor=red];
subgraph cluster_29 {
color=blue
85 [label="Enter block"];
84 [label="Enter block"];
subgraph cluster_30 {
color=blue
86 [label="Function call arguments enter"];
87 [label="Access variable D|/IssuesListUserProfile.issueListView|"];
88 [label="Access variable R|<local>/issueListView|"];
89 [label="Function call arguments exit"];
85 [label="Function call arguments enter"];
86 [label="Access variable D|/IssuesListUserProfile.issueListView|"];
87 [label="Access variable R|<local>/issueListView|"];
88 [label="Function call arguments exit"];
}
90 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.setValue: R|kotlin/Unit|>|(...)" style="filled" fillcolor=yellow];
91 [label="Jump: ^ this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.setValue: R|kotlin/Unit|>|(this@R|/IssuesListUserProfile|, ::R|/IssuesListUserProfile.issueListView|, R|<local>/issueListView|)"];
92 [label="Stub" style="filled" fillcolor=gray];
93 [label="Exit block" style="filled" fillcolor=gray];
89 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.setValue: R|kotlin/Unit|>|(...)" style="filled" fillcolor=yellow];
90 [label="Jump: ^ this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride<kotlin/properties/ReadWriteProperty.setValue: R|kotlin/Unit|>|(this@R|/IssuesListUserProfile|, ::R|/IssuesListUserProfile.issueListView|, R|<local>/issueListView|)"];
91 [label="Stub" style="filled" fillcolor=gray];
92 [label="Exit block" style="filled" fillcolor=gray];
}
94 [label="Exit function <setter>" style="filled" fillcolor=red];
93 [label="Exit function <setter>" style="filled" fillcolor=red];
}
83 -> {84};
84 -> {85};
85 -> {86};
86 -> {87};
87 -> {88};
88 -> {89};
89 -> {90};
90 -> {91};
91 -> {94};
90 -> {93};
90 -> {91} [style=dotted];
91 -> {92} [style=dotted];
92 -> {93} [style=dotted];
93 -> {94} [style=dotted];
}