[FIR] Resolve elvis call as special synthetic call

Before that commit we desugared `a ?: b` as

when (val elvis = a) {
    null -> b
    else -> elvis
}

It was incorrect, because `a` should be resolved in dependent mode,
  but when it was `elvis` initializer it was resolved in independent
  mode, so we can't infer type for `a` in some complex cases
This commit is contained in:
Dmitriy Novozhilov
2020-06-30 15:31:24 +03:00
parent b49b3245af
commit 102c9c08d0
48 changed files with 1560 additions and 1828 deletions
@@ -24,15 +24,7 @@ FILE: delegateWithLambda.kt
} }
public final val x: R|kotlin/String|by R|/lazy|<R|kotlin/String|>(<L> = lazy@fun <anonymous>(): R|kotlin/String| { public final val x: R|kotlin/String|by R|/lazy|<R|kotlin/String|>(<L> = lazy@fun <anonymous>(): R|kotlin/String| {
lval y: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = (R|/getAny|() as? R|kotlin/String|)) { lval y: R|kotlin/String| = (R|/getAny|() as? R|kotlin/String|) ?: String()
==($subj$, Null(null)) -> {
String()
}
else -> {
R|<local>/<elvis>|
}
}
^ R|<local>/y| ^ R|<local>/y|
} }
) )
@@ -16,27 +16,11 @@ FILE: test.kt
} }
public final fun test1(x: R|AnotherClass?|): R|kotlin/Unit| { public final fun test1(x: R|AnotherClass?|): R|kotlin/Unit| {
lval bar: R|kotlin/CharSequence| = when (lval <elvis>: R|kotlin/CharSequence?| = R|<local>/x|?.{ $subj$.R|/AnotherClass.bar| }) { lval bar: R|kotlin/CharSequence| = R|<local>/x|?.{ $subj$.R|/AnotherClass.bar| } ?: ^test1 Unit
==($subj$, Null(null)) -> {
^test1 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/AnotherClass.bar| R|<local>/x|.R|/AnotherClass.bar|
} }
public final fun test2(x: R|SomeClass?|): R|kotlin/Unit| { public final fun test2(x: R|SomeClass?|): R|kotlin/Unit| {
lval bar: R|kotlin/CharSequence| = when (lval <elvis>: R|kotlin/CharSequence?| = R|<local>/x|?.{ $subj$.R|/SomeClass.bar| }) { lval bar: R|kotlin/CharSequence| = R|<local>/x|?.{ $subj$.R|/SomeClass.bar| } ?: ^test2 Unit
==($subj$, Null(null)) -> {
^test2 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/SomeClass.bar| R|<local>/x|.R|/SomeClass.bar|
} }
public final fun test3(x: R|AnotherClass?|): R|kotlin/Unit| { public final fun test3(x: R|AnotherClass?|): R|kotlin/Unit| {
@@ -58,62 +42,22 @@ FILE: test.kt
} }
public final fun test5(x: R|AnotherClass?|): R|kotlin/Unit| { public final fun test5(x: R|AnotherClass?|): R|kotlin/Unit| {
lval bar: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = (R|<local>/x|?.{ $subj$.R|/AnotherClass.bar| } as? R|kotlin/String|)) { lval bar: R|kotlin/String| = (R|<local>/x|?.{ $subj$.R|/AnotherClass.bar| } as? R|kotlin/String|) ?: ^test5 Unit
==($subj$, Null(null)) -> {
^test5 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/AnotherClass.foo| R|<local>/x|.R|/AnotherClass.foo|
} }
public final fun test6(x: R|SomeClass?|): R|kotlin/Unit| { public final fun test6(x: R|SomeClass?|): R|kotlin/Unit| {
lval bar: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = (R|<local>/x|?.{ $subj$.R|/SomeClass.bar| } as? R|kotlin/String|)) { lval bar: R|kotlin/String| = (R|<local>/x|?.{ $subj$.R|/SomeClass.bar| } as? R|kotlin/String|) ?: ^test6 Unit
==($subj$, Null(null)) -> {
^test6 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/SomeClass.foo| R|<local>/x|.R|/SomeClass.foo|
} }
public final fun test7(x: R|AnotherClass?|): R|kotlin/Unit| { public final fun test7(x: R|AnotherClass?|): R|kotlin/Unit| {
lval baz: R|kotlin/Boolean| = when (lval <elvis>: R|kotlin/Boolean?| = (R|<local>/x|?.{ $subj$.R|/AnotherClass.baz|() } as? R|kotlin/Boolean|)) { lval baz: R|kotlin/Boolean| = (R|<local>/x|?.{ $subj$.R|/AnotherClass.baz|() } as? R|kotlin/Boolean|) ?: ^test7 Unit
==($subj$, Null(null)) -> {
^test7 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/AnotherClass.foo| R|<local>/x|.R|/AnotherClass.foo|
} }
public final fun test8(x: R|AnotherClass?|): R|kotlin/Unit| { public final fun test8(x: R|AnotherClass?|): R|kotlin/Unit| {
lval bar: R|kotlin/CharSequence| = when (lval <elvis>: R|kotlin/CharSequence?| = R|<local>/x|?.{ $subj$.R|/AnotherClass.bar| }) { lval bar: R|kotlin/CharSequence| = R|<local>/x|?.{ $subj$.R|/AnotherClass.bar| } ?: ^test8 Unit
==($subj$, Null(null)) -> {
^test8 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/AnotherClass.foo| R|<local>/x|.R|/AnotherClass.foo|
} }
public final fun test9(x: R|AnotherClass?|): R|kotlin/Unit| { public final fun test9(x: R|AnotherClass?|): R|kotlin/Unit| {
lval baz: R|kotlin/Any| = when (lval <elvis>: R|kotlin/Any?| = R|<local>/x|?.{ $subj$.R|/AnotherClass.baz|() }) { lval baz: R|kotlin/Any| = R|<local>/x|?.{ $subj$.R|/AnotherClass.baz|() } ?: ^test9 Unit
==($subj$, Null(null)) -> {
^test9 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/AnotherClass.foo| R|<local>/x|.R|/AnotherClass.foo|
} }
@@ -0,0 +1,18 @@
// ISSUE: KT-39012
interface A
fun <T> foo(f: (MutableList<T>) -> Unit): List<T>? = TODO()
fun <T> listOf(): List<T> = TODO()
fun bar1(w: List<CharSequence>): List<CharSequence>? {
return foo { container ->
container.add("")
} ?: w
}
fun bar2(): List<CharSequence>? {
return foo { container ->
container.add("")
} ?: listOf()
}
@@ -0,0 +1,21 @@
FILE: lambdaInElvis.kt
public abstract interface A : R|kotlin/Any| {
}
public final fun <T> foo(f: R|(kotlin/collections/MutableList<T>) -> kotlin/Unit|): R|kotlin/collections/List<T>?| {
^foo R|kotlin/TODO|()
}
public final fun <T> listOf(): R|kotlin/collections/List<T>| {
^listOf R|kotlin/TODO|()
}
public final fun bar1(w: R|kotlin/collections/List<kotlin/CharSequence>|): R|kotlin/collections/List<kotlin/CharSequence>?| {
^bar1 R|/foo|<R|kotlin/CharSequence|>(<L> = foo@fun <anonymous>(container: R|kotlin/collections/MutableList<kotlin/CharSequence>|): R|kotlin/Unit| {
^ R|<local>/container|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(String())
}
) ?: R|<local>/w|
}
public final fun bar2(): R|kotlin/collections/List<kotlin/CharSequence>?| {
^bar2 R|/foo|<R|kotlin/CharSequence|>(<L> = foo@fun <anonymous>(container: R|kotlin/collections/MutableList<kotlin/CharSequence>|): R|kotlin/Unit| {
^ R|<local>/container|.R|FakeOverride<kotlin/collections/MutableList.add: R|kotlin/Boolean|>|(String())
}
) ?: R|/listOf|<R|kotlin/CharSequence|>()
}
@@ -1,12 +1,4 @@
FILE: invokeInWhenSubjectVariableInitializer.kt FILE: invokeInWhenSubjectVariableInitializer.kt
public final fun test(func: R|() -> kotlin/String?|): R|kotlin/Unit| { public final fun test(func: R|() -> kotlin/String?|): R|kotlin/Unit| {
lval x: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = R|<local>/func|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/String?|>|()) { lval x: R|kotlin/String| = R|<local>/func|.R|FakeOverride<kotlin/Function0.invoke: R|kotlin/String?|>|() ?: String()
==($subj$, Null(null)) -> {
String()
}
else -> {
R|<local>/<elvis>|
}
}
} }
@@ -366,81 +366,75 @@ digraph boundSmartcasts_kt {
subgraph cluster_34 { subgraph cluster_34 {
color=blue color=blue
130 [label="Enter block"]; 130 [label="Enter block"];
subgraph cluster_35 { 131 [label="Access variable R|<local>/d|"];
color=blue 132 [label="Access variable R|/D.any|"];
131 [label="Enter when"]; 133 [label="Exit lhs of ?:"];
132 [label="Access variable R|<local>/d|"]; 134 [label="Enter rhs of ?:"];
133 [label="Access variable R|/D.any|"]; 135 [label="Jump: ^test_5 Unit"];
134 [label="Variable declaration: lval <elvis>: R|kotlin/Any?|"]; 136 [label="Stub" style="filled" fillcolor=gray];
subgraph cluster_36 { 137 [label="Lhs of ?: is not null"];
color=blue 138 [label="Exit ?:"];
135 [label="Enter when branch condition "]; 139 [label="Variable declaration: lval a: R|kotlin/Any|"];
136 [label="Const: Null(null)"]; 140 [label="Access variable R|<local>/a|"];
137 [label="Operator =="]; 141 [label="Function call: R|<local>/a|.R|/baz|()"];
138 [label="Exit when branch condition"]; 142 [label="Access variable R|<local>/d|"];
} 143 [label="Access variable R|/D.any|"];
subgraph cluster_37 { 144 [label="Function call: R|<local>/d|.R|/D.any|.R|/baz|()"];
color=blue 145 [label="Access variable R|<local>/a|"];
139 [label="Enter when branch condition else"]; 146 [label="Type operator: (R|<local>/a| as R|A|)"];
140 [label="Exit when branch condition"]; 147 [label="Access variable R|<local>/a|"];
} 148 [label="Function call: R|<local>/a|.R|/A.foo|()"];
141 [label="Enter when branch result"]; 149 [label="Exit block"];
subgraph cluster_38 {
color=blue
142 [label="Enter block"];
143 [label="Access variable R|<local>/<elvis>|"];
144 [label="Exit block"];
}
145 [label="Exit when branch result"];
146 [label="Enter when branch result"];
subgraph cluster_39 {
color=blue
147 [label="Enter block"];
148 [label="Jump: ^test_5 Unit"];
149 [label="Stub" style="filled" fillcolor=gray];
150 [label="Exit block" style="filled" fillcolor=gray];
}
151 [label="Exit when branch result" style="filled" fillcolor=gray];
152 [label="Exit when"];
}
153 [label="Variable declaration: lval a: R|kotlin/Any|"];
154 [label="Access variable R|<local>/a|"];
155 [label="Function call: R|<local>/a|.R|/baz|()"];
156 [label="Access variable R|<local>/d|"];
157 [label="Access variable R|/D.any|"];
158 [label="Function call: R|<local>/d|.R|/D.any|.R|/baz|()"];
159 [label="Access variable R|<local>/a|"];
160 [label="Type operator: (R|<local>/a| as R|A|)"];
161 [label="Access variable R|<local>/a|"];
162 [label="Function call: R|<local>/a|.R|/A.foo|()"];
163 [label="Exit block"];
} }
164 [label="Exit function test_5" style="filled" fillcolor=red]; 150 [label="Exit function test_5" style="filled" fillcolor=red];
} }
129 -> {130}; 129 -> {130};
130 -> {131}; 130 -> {131};
131 -> {132}; 131 -> {132};
132 -> {133}; 132 -> {133};
133 -> {134}; 133 -> {137 134};
134 -> {135}; 134 -> {135};
135 -> {136}; 135 -> {150};
136 -> {137}; 135 -> {136} [style=dotted];
136 -> {138} [style=dotted];
137 -> {138}; 137 -> {138};
138 -> {146 139}; 138 -> {139};
139 -> {140}; 139 -> {140};
140 -> {141}; 140 -> {141};
141 -> {142}; 141 -> {142};
142 -> {143}; 142 -> {143};
143 -> {144}; 143 -> {144};
144 -> {145}; 144 -> {145};
145 -> {152}; 145 -> {146};
146 -> {147}; 146 -> {147};
147 -> {148}; 147 -> {148};
148 -> {164}; 148 -> {149};
148 -> {149} [style=dotted]; 149 -> {150};
149 -> {150} [style=dotted];
150 -> {151} [style=dotted]; subgraph cluster_35 {
151 -> {152} [style=dotted]; color=red
151 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_36 {
color=blue
152 [label="Enter block"];
153 [label="Access variable R|<local>/d1|"];
154 [label="Access variable R|/D.any|"];
155 [label="Variable declaration: lval a: R|kotlin/Any?|"];
156 [label="Access variable R|<local>/a|"];
157 [label="Type operator: (R|<local>/a| as R|A|)"];
158 [label="Access variable R|<local>/a|"];
159 [label="Function call: R|<local>/a|.R|/A.foo|()"];
160 [label="Access variable R|<local>/d1|"];
161 [label="Access variable R|/D.any|"];
162 [label="Function call: R|<local>/d1|.R|/D.any|.R|/A.foo|()"];
163 [label="Access variable R|<local>/d1|"];
164 [label="Access variable R|/D.any|"];
165 [label="Function call: R|<local>/d1|.R|/D.any|.R|/baz|()"];
166 [label="Exit block"];
}
167 [label="Exit function test_6" style="filled" fillcolor=red];
}
151 -> {152};
152 -> {153}; 152 -> {153};
153 -> {154}; 153 -> {154};
154 -> {155}; 154 -> {155};
@@ -453,95 +447,58 @@ digraph boundSmartcasts_kt {
161 -> {162}; 161 -> {162};
162 -> {163}; 162 -> {163};
163 -> {164}; 163 -> {164};
164 -> {165};
subgraph cluster_40 {
color=red
165 [label="Enter function test_6" style="filled" fillcolor=red];
subgraph cluster_41 {
color=blue
166 [label="Enter block"];
167 [label="Access variable R|<local>/d1|"];
168 [label="Access variable R|/D.any|"];
169 [label="Variable declaration: lval a: R|kotlin/Any?|"];
170 [label="Access variable R|<local>/a|"];
171 [label="Type operator: (R|<local>/a| as R|A|)"];
172 [label="Access variable R|<local>/a|"];
173 [label="Function call: R|<local>/a|.R|/A.foo|()"];
174 [label="Access variable R|<local>/d1|"];
175 [label="Access variable R|/D.any|"];
176 [label="Function call: R|<local>/d1|.R|/D.any|.R|/A.foo|()"];
177 [label="Access variable R|<local>/d1|"];
178 [label="Access variable R|/D.any|"];
179 [label="Function call: R|<local>/d1|.R|/D.any|.R|/baz|()"];
180 [label="Exit block"];
}
181 [label="Exit function test_6" style="filled" fillcolor=red];
}
165 -> {166}; 165 -> {166};
166 -> {167}; 166 -> {167};
167 -> {168};
subgraph cluster_37 {
color=red
168 [label="Enter function test_7" style="filled" fillcolor=red];
subgraph cluster_38 {
color=blue
169 [label="Enter block"];
170 [label="Access variable R|<local>/d1|"];
171 [label="Enter safe call"];
172 [label="Access variable R|/D.any|"];
173 [label="Exit safe call"];
174 [label="Variable declaration: lval a: R|kotlin/Any?|"];
175 [label="Access variable R|<local>/d2|"];
176 [label="Enter safe call"];
177 [label="Access variable R|/D.any|"];
178 [label="Exit safe call"];
179 [label="Variable declaration: lval b: R|kotlin/Any?|"];
180 [label="Access variable R|<local>/a|"];
181 [label="Type operator: (R|<local>/a| as R|A|)"];
182 [label="Access variable R|<local>/a|"];
183 [label="Function call: R|<local>/a|.R|/A.foo|()"];
184 [label="Access variable R|<local>/b|"];
185 [label="Type operator: (R|<local>/b| as R|B|)"];
186 [label="Access variable R|<local>/b|"];
187 [label="Function call: R|<local>/b|.R|/B.bar|()"];
188 [label="Exit block"];
}
189 [label="Exit function test_7" style="filled" fillcolor=red];
}
168 -> {169}; 168 -> {169};
169 -> {170}; 169 -> {170};
170 -> {171}; 170 -> {171 173};
171 -> {172}; 171 -> {172};
172 -> {173}; 172 -> {173};
173 -> {174}; 173 -> {174};
174 -> {175}; 174 -> {175};
175 -> {176}; 175 -> {176 178};
176 -> {177}; 176 -> {177};
177 -> {178}; 177 -> {178};
178 -> {179}; 178 -> {179};
179 -> {180}; 179 -> {180};
180 -> {181}; 180 -> {181};
181 -> {182};
subgraph cluster_42 {
color=red
182 [label="Enter function test_7" style="filled" fillcolor=red];
subgraph cluster_43 {
color=blue
183 [label="Enter block"];
184 [label="Access variable R|<local>/d1|"];
185 [label="Enter safe call"];
186 [label="Access variable R|/D.any|"];
187 [label="Exit safe call"];
188 [label="Variable declaration: lval a: R|kotlin/Any?|"];
189 [label="Access variable R|<local>/d2|"];
190 [label="Enter safe call"];
191 [label="Access variable R|/D.any|"];
192 [label="Exit safe call"];
193 [label="Variable declaration: lval b: R|kotlin/Any?|"];
194 [label="Access variable R|<local>/a|"];
195 [label="Type operator: (R|<local>/a| as R|A|)"];
196 [label="Access variable R|<local>/a|"];
197 [label="Function call: R|<local>/a|.R|/A.foo|()"];
198 [label="Access variable R|<local>/b|"];
199 [label="Type operator: (R|<local>/b| as R|B|)"];
200 [label="Access variable R|<local>/b|"];
201 [label="Function call: R|<local>/b|.R|/B.bar|()"];
202 [label="Exit block"];
}
203 [label="Exit function test_7" style="filled" fillcolor=red];
}
182 -> {183}; 182 -> {183};
183 -> {184}; 183 -> {184};
184 -> {185 187}; 184 -> {185};
185 -> {186}; 185 -> {186};
186 -> {187}; 186 -> {187};
187 -> {188}; 187 -> {188};
188 -> {189}; 188 -> {189};
189 -> {190 192};
190 -> {191};
191 -> {192};
192 -> {193};
193 -> {194};
194 -> {195};
195 -> {196};
196 -> {197};
197 -> {198};
198 -> {199};
199 -> {200};
200 -> {201};
201 -> {202};
202 -> {203};
} }
@@ -70,15 +70,7 @@ FILE: boundSmartcasts.kt
public final fun R|kotlin/Any|.baz(): R|kotlin/Unit| { public final fun R|kotlin/Any|.baz(): R|kotlin/Unit| {
} }
public final fun test_5(d: R|D|): R|kotlin/Unit| { public final fun test_5(d: R|D|): R|kotlin/Unit| {
lval a: R|kotlin/Any| = when (lval <elvis>: R|kotlin/Any?| = R|<local>/d|.R|/D.any|) { lval a: R|kotlin/Any| = R|<local>/d|.R|/D.any| ?: ^test_5 Unit
==($subj$, Null(null)) -> {
^test_5 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/a|.R|/baz|() R|<local>/a|.R|/baz|()
R|<local>/d|.R|/D.any|.R|/baz|() R|<local>/d|.R|/D.any|.R|/baz|()
(R|<local>/a| as R|A|) (R|<local>/a| as R|A|)
@@ -36,122 +36,102 @@ digraph elvis_kt {
subgraph cluster_6 { subgraph cluster_6 {
color=blue color=blue
9 [label="Enter when branch condition "]; 9 [label="Enter when branch condition "];
subgraph cluster_7 { 10 [label="Access variable R|<local>/x|"];
color=blue 11 [label="Enter safe call"];
10 [label="Enter when"]; 12 [label="Access variable R|/A.b|"];
11 [label="Access variable R|<local>/x|"]; 13 [label="Exit safe call"];
12 [label="Enter safe call"]; 14 [label="Exit lhs of ?:"];
13 [label="Access variable R|/A.b|"]; 15 [label="Enter rhs of ?:"];
14 [label="Exit safe call"]; 16 [label="Jump: ^test_1 Unit"];
15 [label="Variable declaration: lval <elvis>: R|kotlin/Boolean?|"]; 17 [label="Stub" style="filled" fillcolor=gray];
subgraph cluster_8 { 18 [label="Lhs of ?: is not null"];
color=blue 19 [label="Exit ?:"];
16 [label="Enter when branch condition "]; 20 [label="Exit when branch condition"];
17 [label="Const: Null(null)"];
18 [label="Operator =="];
19 [label="Exit when branch condition"];
}
subgraph cluster_9 {
color=blue
20 [label="Enter when branch condition else"];
21 [label="Exit when branch condition"];
}
22 [label="Enter when branch result"];
subgraph cluster_10 {
color=blue
23 [label="Enter block"];
24 [label="Access variable R|<local>/<elvis>|"];
25 [label="Exit block"];
}
26 [label="Exit when branch result"];
27 [label="Enter when branch result"];
subgraph cluster_11 {
color=blue
28 [label="Enter block"];
29 [label="Jump: ^test_1 Unit"];
30 [label="Stub" style="filled" fillcolor=gray];
31 [label="Exit block" style="filled" fillcolor=gray];
}
32 [label="Exit when branch result" style="filled" fillcolor=gray];
33 [label="Exit when"];
}
34 [label="Exit when branch condition"];
} }
35 [label="Synthetic else branch"]; 21 [label="Synthetic else branch"];
36 [label="Enter when branch result"]; 22 [label="Enter when branch result"];
subgraph cluster_12 { subgraph cluster_7 {
color=blue color=blue
37 [label="Enter block"]; 23 [label="Enter block"];
38 [label="Access variable R|<local>/x|"]; 24 [label="Access variable R|<local>/x|"];
39 [label="Function call: R|<local>/x|.R|/A.foo|()"]; 25 [label="Function call: R|<local>/x|.R|/A.foo|()"];
40 [label="Exit block"]; 26 [label="Exit block"];
} }
41 [label="Exit when branch result"]; 27 [label="Exit when branch result"];
42 [label="Exit when"]; 28 [label="Exit when"];
} }
43 [label="Exit block"]; 29 [label="Exit block"];
} }
44 [label="Exit function test_1" style="filled" fillcolor=red]; 30 [label="Exit function test_1" style="filled" fillcolor=red];
} }
6 -> {7}; 6 -> {7};
7 -> {8}; 7 -> {8};
8 -> {9}; 8 -> {9};
9 -> {10}; 9 -> {10};
10 -> {11}; 10 -> {11 13};
11 -> {12 14}; 11 -> {12};
12 -> {13}; 12 -> {13};
13 -> {14}; 13 -> {14};
14 -> {15}; 14 -> {18 15};
15 -> {16}; 15 -> {16};
16 -> {17}; 16 -> {30};
17 -> {18}; 16 -> {17} [style=dotted];
17 -> {19} [style=dotted];
18 -> {19}; 18 -> {19};
19 -> {27 20}; 19 -> {20};
20 -> {21}; 20 -> {22 21};
21 -> {22}; 21 -> {28};
22 -> {23}; 22 -> {23};
23 -> {24}; 23 -> {24};
24 -> {25}; 24 -> {25};
25 -> {26}; 25 -> {26};
26 -> {33}; 26 -> {27};
27 -> {28}; 27 -> {28};
28 -> {29}; 28 -> {29};
29 -> {44}; 29 -> {30};
29 -> {30} [style=dotted];
30 -> {31} [style=dotted];
31 -> {32} [style=dotted];
32 -> {33} [style=dotted];
33 -> {34};
34 -> {36 35};
35 -> {42};
36 -> {37};
37 -> {38};
38 -> {39};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {44};
subgraph cluster_13 { subgraph cluster_8 {
color=red color=red
45 [label="Enter function test2" style="filled" fillcolor=red]; 31 [label="Enter function test2" style="filled" fillcolor=red];
subgraph cluster_14 { subgraph cluster_9 {
color=blue color=blue
46 [label="Enter block"]; 32 [label="Enter block"];
subgraph cluster_15 { subgraph cluster_10 {
color=blue
33 [label="Enter when"];
subgraph cluster_11 {
color=blue
34 [label="Enter when branch condition "];
35 [label="Access variable R|<local>/b|"];
36 [label="Type operator: (R|<local>/b| !is R|kotlin/String|)"];
37 [label="Exit when branch condition"];
}
38 [label="Synthetic else branch"];
39 [label="Enter when branch result"];
subgraph cluster_12 {
color=blue
40 [label="Enter block"];
41 [label="Const: String()"];
42 [label="Jump: ^test2 String()"];
43 [label="Stub" style="filled" fillcolor=gray];
44 [label="Exit block" style="filled" fillcolor=gray];
}
45 [label="Exit when branch result" style="filled" fillcolor=gray];
46 [label="Exit when"];
}
subgraph cluster_13 {
color=blue color=blue
47 [label="Enter when"]; 47 [label="Enter when"];
subgraph cluster_16 { subgraph cluster_14 {
color=blue color=blue
48 [label="Enter when branch condition "]; 48 [label="Enter when branch condition "];
49 [label="Access variable R|<local>/b|"]; 49 [label="Access variable R|<local>/a|"];
50 [label="Type operator: (R|<local>/b| !is R|kotlin/String|)"]; 50 [label="Type operator: (R|<local>/a| !is R|kotlin/String?|)"];
51 [label="Exit when branch condition"]; 51 [label="Exit when branch condition"];
} }
52 [label="Synthetic else branch"]; 52 [label="Synthetic else branch"];
53 [label="Enter when branch result"]; 53 [label="Enter when branch result"];
subgraph cluster_17 { subgraph cluster_15 {
color=blue color=blue
54 [label="Enter block"]; 54 [label="Enter block"];
55 [label="Const: String()"]; 55 [label="Const: String()"];
@@ -162,79 +142,34 @@ digraph elvis_kt {
59 [label="Exit when branch result" style="filled" fillcolor=gray]; 59 [label="Exit when branch result" style="filled" fillcolor=gray];
60 [label="Exit when"]; 60 [label="Exit when"];
} }
subgraph cluster_18 { 61 [label="Access variable R|<local>/a|"];
color=blue 62 [label="Exit lhs of ?:"];
61 [label="Enter when"]; 63 [label="Enter rhs of ?:"];
subgraph cluster_19 { 64 [label="Access variable R|<local>/b|"];
color=blue 65 [label="Lhs of ?: is not null"];
62 [label="Enter when branch condition "]; 66 [label="Exit ?:"];
63 [label="Access variable R|<local>/a|"]; 67 [label="Jump: ^test2 R|<local>/a| ?: R|<local>/b|"];
64 [label="Type operator: (R|<local>/a| !is R|kotlin/String?|)"]; 68 [label="Stub" style="filled" fillcolor=gray];
65 [label="Exit when branch condition"]; 69 [label="Exit block" style="filled" fillcolor=gray];
}
66 [label="Synthetic else branch"];
67 [label="Enter when branch result"];
subgraph cluster_20 {
color=blue
68 [label="Enter block"];
69 [label="Const: String()"];
70 [label="Jump: ^test2 String()"];
71 [label="Stub" style="filled" fillcolor=gray];
72 [label="Exit block" style="filled" fillcolor=gray];
}
73 [label="Exit when branch result" style="filled" fillcolor=gray];
74 [label="Exit when"];
}
subgraph cluster_21 {
color=blue
75 [label="Enter when"];
76 [label="Access variable R|<local>/a|"];
77 [label="Variable declaration: lval <elvis>: R|kotlin/String?|"];
subgraph cluster_22 {
color=blue
78 [label="Enter when branch condition "];
79 [label="Const: Null(null)"];
80 [label="Operator =="];
81 [label="Exit when branch condition"];
}
subgraph cluster_23 {
color=blue
82 [label="Enter when branch condition else"];
83 [label="Exit when branch condition"];
}
84 [label="Enter when branch result"];
subgraph cluster_24 {
color=blue
85 [label="Enter block"];
86 [label="Access variable R|<local>/<elvis>|"];
87 [label="Exit block"];
}
88 [label="Exit when branch result"];
89 [label="Enter when branch result"];
subgraph cluster_25 {
color=blue
90 [label="Enter block"];
91 [label="Access variable R|<local>/b|"];
92 [label="Exit block"];
}
93 [label="Exit when branch result"];
94 [label="Exit when"];
}
95 [label="Jump: ^test2 when (lval <elvis>: R|kotlin/String?| = R|<local>/a|) {
==($subj$, Null(null)) -> {
R|<local>/b|
}
else -> {
R|<local>/<elvis>|
}
}
"];
96 [label="Stub" style="filled" fillcolor=gray];
97 [label="Exit block" style="filled" fillcolor=gray];
} }
98 [label="Exit function test2" style="filled" fillcolor=red]; 70 [label="Exit function test2" style="filled" fillcolor=red];
} }
45 -> {46}; 31 -> {32};
32 -> {33};
33 -> {34};
34 -> {35};
35 -> {36};
36 -> {37};
37 -> {39 38};
38 -> {46};
39 -> {40};
40 -> {41};
41 -> {42};
42 -> {70};
42 -> {43} [style=dotted];
43 -> {44} [style=dotted];
44 -> {45} [style=dotted];
45 -> {46} [style=dotted];
46 -> {47}; 46 -> {47};
47 -> {48}; 47 -> {48};
48 -> {49}; 48 -> {49};
@@ -245,50 +180,21 @@ digraph elvis_kt {
53 -> {54}; 53 -> {54};
54 -> {55}; 54 -> {55};
55 -> {56}; 55 -> {56};
56 -> {98}; 56 -> {70};
56 -> {57} [style=dotted]; 56 -> {57} [style=dotted];
57 -> {58} [style=dotted]; 57 -> {58} [style=dotted];
58 -> {59} [style=dotted]; 58 -> {59} [style=dotted];
59 -> {60} [style=dotted]; 59 -> {60} [style=dotted];
60 -> {61}; 60 -> {61};
61 -> {62}; 61 -> {62};
62 -> {63}; 62 -> {65 63};
63 -> {64}; 63 -> {64};
64 -> {65}; 64 -> {66};
65 -> {67 66}; 65 -> {66};
66 -> {74}; 66 -> {67};
67 -> {68}; 67 -> {70};
68 -> {69}; 67 -> {68} [style=dotted];
69 -> {70}; 68 -> {69} [style=dotted];
70 -> {98}; 69 -> {70} [style=dotted];
70 -> {71} [style=dotted];
71 -> {72} [style=dotted];
72 -> {73} [style=dotted];
73 -> {74} [style=dotted];
74 -> {75};
75 -> {76};
76 -> {77};
77 -> {78};
78 -> {79};
79 -> {80};
80 -> {81};
81 -> {89 82};
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {86};
86 -> {87};
87 -> {88};
88 -> {94};
89 -> {90};
90 -> {91};
91 -> {92};
92 -> {93};
93 -> {94};
94 -> {95};
95 -> {98};
95 -> {96} [style=dotted];
96 -> {97} [style=dotted];
97 -> {98} [style=dotted];
} }
@@ -8,15 +8,7 @@ FILE: elvis.kt
} }
public final fun test_1(x: R|A?|): R|kotlin/Unit| { public final fun test_1(x: R|A?|): R|kotlin/Unit| {
when () { when () {
when (lval <elvis>: R|kotlin/Boolean?| = R|<local>/x|?.{ $subj$.R|/A.b| }) { R|<local>/x|?.{ $subj$.R|/A.b| } ?: ^test_1 Unit -> {
==($subj$, Null(null)) -> {
^test_1 Unit
}
else -> {
R|<local>/<elvis>|
}
}
-> {
R|<local>/x|.R|/A.foo|() R|<local>/x|.R|/A.foo|()
} }
} }
@@ -35,13 +27,5 @@ FILE: elvis.kt
} }
} }
^test2 when (lval <elvis>: R|kotlin/String?| = R|<local>/a|) { ^test2 R|<local>/a| ?: R|<local>/b|
==($subj$, Null(null)) -> {
R|<local>/b|
}
else -> {
R|<local>/<elvis>|
}
}
} }
@@ -434,104 +434,61 @@ digraph returns_kt {
151 [label="Access variable R|<local>/a|"]; 151 [label="Access variable R|<local>/a|"];
152 [label="Type operator: (R|<local>/a| as? R|kotlin/String|)"]; 152 [label="Type operator: (R|<local>/a| as? R|kotlin/String|)"];
153 [label="Variable declaration: lval s: R|kotlin/String?|"]; 153 [label="Variable declaration: lval s: R|kotlin/String?|"];
154 [label="Access variable R|<local>/s|"];
155 [label="Enter safe call"];
156 [label="Access variable R|/ext|"];
157 [label="Exit safe call"];
158 [label="Exit lhs of ?:"];
159 [label="Enter rhs of ?:"];
160 [label="Jump: ^test_4 Unit"];
161 [label="Stub" style="filled" fillcolor=gray];
162 [label="Lhs of ?: is not null"];
163 [label="Exit ?:"];
164 [label="Variable declaration: lval length: R|kotlin/Int|"];
165 [label="Postponed enter to lambda"];
subgraph cluster_42 { subgraph cluster_42 {
color=blue color=blue
154 [label="Enter when"]; 170 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
155 [label="Access variable R|<local>/s|"];
156 [label="Enter safe call"];
157 [label="Access variable R|/ext|"];
158 [label="Exit safe call"];
159 [label="Variable declaration: lval <elvis>: R|kotlin/Int?|"];
subgraph cluster_43 { subgraph cluster_43 {
color=blue color=blue
160 [label="Enter when branch condition "]; 171 [label="Enter block"];
161 [label="Const: Null(null)"]; 172 [label="Access variable R|<local>/s|"];
162 [label="Operator =="]; 173 [label="Access variable R|kotlin/String.length|"];
163 [label="Exit when branch condition"]; 174 [label="Exit block"];
} }
subgraph cluster_44 { 175 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
color=blue
164 [label="Enter when branch condition else"];
165 [label="Exit when branch condition"];
}
166 [label="Enter when branch result"];
subgraph cluster_45 {
color=blue
167 [label="Enter block"];
168 [label="Access variable R|<local>/<elvis>|"];
169 [label="Exit block"];
}
170 [label="Exit when branch result"];
171 [label="Enter when branch result"];
subgraph cluster_46 {
color=blue
172 [label="Enter block"];
173 [label="Jump: ^test_4 Unit"];
174 [label="Stub" style="filled" fillcolor=gray];
175 [label="Exit block" style="filled" fillcolor=gray];
}
176 [label="Exit when branch result" style="filled" fillcolor=gray];
177 [label="Exit when"];
} }
178 [label="Variable declaration: lval length: R|kotlin/Int|"]; 166 [label="Postponed exit from lambda"];
179 [label="Postponed enter to lambda"]; 167 [label="Function call: R|/runHigherOrder|<R|kotlin/Int|>(...)"];
subgraph cluster_47 { 168 [label="Exit block"];
color=blue
184 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_48 {
color=blue
185 [label="Enter block"];
186 [label="Access variable R|<local>/s|"];
187 [label="Access variable R|kotlin/String.length|"];
188 [label="Exit block"];
}
189 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
180 [label="Postponed exit from lambda"];
181 [label="Function call: R|/runHigherOrder|<R|kotlin/Int|>(...)"];
182 [label="Exit block"];
} }
183 [label="Exit function test_4" style="filled" fillcolor=red]; 169 [label="Exit function test_4" style="filled" fillcolor=red];
} }
149 -> {150}; 149 -> {150};
150 -> {151}; 150 -> {151};
151 -> {152}; 151 -> {152};
152 -> {153}; 152 -> {153};
153 -> {154}; 153 -> {154};
154 -> {155}; 154 -> {155 157};
155 -> {156 158}; 155 -> {156};
156 -> {157}; 156 -> {157};
157 -> {158}; 157 -> {158};
158 -> {159}; 158 -> {162 159};
159 -> {160}; 159 -> {160};
160 -> {161}; 160 -> {169};
161 -> {162}; 160 -> {161} [style=dotted];
161 -> {163} [style=dotted];
162 -> {163}; 162 -> {163};
163 -> {171 164}; 163 -> {164};
164 -> {165}; 164 -> {165};
165 -> {166}; 165 -> {166 170};
166 -> {167}; 166 -> {167};
167 -> {168}; 167 -> {168};
168 -> {169}; 168 -> {169};
169 -> {170}; 170 -> {171};
170 -> {177};
171 -> {172}; 171 -> {172};
172 -> {173}; 172 -> {173};
173 -> {183}; 173 -> {174};
173 -> {174} [style=dotted]; 174 -> {175};
174 -> {175} [style=dotted];
175 -> {176} [style=dotted];
176 -> {177} [style=dotted];
177 -> {178};
178 -> {179};
179 -> {180 184};
180 -> {181};
181 -> {182};
182 -> {183};
184 -> {185};
185 -> {186};
186 -> {187};
187 -> {188};
188 -> {189};
} }
@@ -74,15 +74,7 @@ FILE: returns.kt
} }
public final fun test_4(a: R|kotlin/Any?|): R|kotlin/Unit| { public final fun test_4(a: R|kotlin/Any?|): R|kotlin/Unit| {
lval s: R|kotlin/String?| = (R|<local>/a| as? R|kotlin/String|) lval s: R|kotlin/String?| = (R|<local>/a| as? R|kotlin/String|)
lval length: R|kotlin/Int| = when (lval <elvis>: R|kotlin/Int?| = R|<local>/s|?.{ $subj$.R|/ext| }) { lval length: R|kotlin/Int| = R|<local>/s|?.{ $subj$.R|/ext| } ?: ^test_4 Unit
==($subj$, Null(null)) -> {
^test_4 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|/runHigherOrder|<R|kotlin/Int|>(<L> = runHigherOrder@fun <anonymous>(): R|kotlin/Int| { R|/runHigherOrder|<R|kotlin/Int|>(<L> = runHigherOrder@fun <anonymous>(): R|kotlin/Int| {
^ R|<local>/s|.R|kotlin/String.length| ^ R|<local>/s|.R|kotlin/String.length|
} }
@@ -50,61 +50,32 @@ digraph smartcastFromArgument_kt {
subgraph cluster_7 { subgraph cluster_7 {
color=blue color=blue
14 [label="Enter when branch condition "]; 14 [label="Enter when branch condition "];
subgraph cluster_8 { 15 [label="Access variable R|<local>/a|"];
color=blue 16 [label="Type operator: (R|<local>/a| as? R|A|)"];
15 [label="Enter when"]; 17 [label="Exit lhs of ?:"];
16 [label="Access variable R|<local>/a|"]; 18 [label="Enter rhs of ?:"];
17 [label="Type operator: (R|<local>/a| as? R|A|)"]; 19 [label="Jump: ^test Unit"];
18 [label="Variable declaration: lval <elvis>: R|A?|"]; 20 [label="Stub" style="filled" fillcolor=gray];
subgraph cluster_9 { 21 [label="Lhs of ?: is not null"];
color=blue 22 [label="Exit ?:"];
19 [label="Enter when branch condition "]; 23 [label="Function call: R|/takeA|(...)"];
20 [label="Const: Null(null)"]; 24 [label="Exit when branch condition"];
21 [label="Operator =="];
22 [label="Exit when branch condition"];
}
subgraph cluster_10 {
color=blue
23 [label="Enter when branch condition else"];
24 [label="Exit when branch condition"];
}
25 [label="Enter when branch result"];
subgraph cluster_11 {
color=blue
26 [label="Enter block"];
27 [label="Access variable R|<local>/<elvis>|"];
28 [label="Exit block"];
}
29 [label="Exit when branch result"];
30 [label="Enter when branch result"];
subgraph cluster_12 {
color=blue
31 [label="Enter block"];
32 [label="Jump: ^test Unit"];
33 [label="Stub" style="filled" fillcolor=gray];
34 [label="Exit block" style="filled" fillcolor=gray];
}
35 [label="Exit when branch result" style="filled" fillcolor=gray];
36 [label="Exit when"];
}
37 [label="Function call: R|/takeA|(...)"];
38 [label="Exit when branch condition"];
} }
39 [label="Synthetic else branch"]; 25 [label="Synthetic else branch"];
40 [label="Enter when branch result"]; 26 [label="Enter when branch result"];
subgraph cluster_13 { subgraph cluster_8 {
color=blue color=blue
41 [label="Enter block"]; 27 [label="Enter block"];
42 [label="Access variable R|<local>/a|"]; 28 [label="Access variable R|<local>/a|"];
43 [label="Function call: R|<local>/a|.R|/A.foo|()"]; 29 [label="Function call: R|<local>/a|.R|/A.foo|()"];
44 [label="Exit block"]; 30 [label="Exit block"];
} }
45 [label="Exit when branch result"]; 31 [label="Exit when branch result"];
46 [label="Exit when"]; 32 [label="Exit when"];
} }
47 [label="Exit block"]; 33 [label="Exit block"];
} }
48 [label="Exit function test" style="filled" fillcolor=red]; 34 [label="Exit function test" style="filled" fillcolor=red];
} }
11 -> {12}; 11 -> {12};
12 -> {13}; 12 -> {13};
@@ -112,37 +83,23 @@ digraph smartcastFromArgument_kt {
14 -> {15}; 14 -> {15};
15 -> {16}; 15 -> {16};
16 -> {17}; 16 -> {17};
17 -> {18}; 17 -> {21 18};
18 -> {19}; 18 -> {19};
19 -> {20}; 19 -> {34};
20 -> {21}; 19 -> {20} [style=dotted];
20 -> {22} [style=dotted];
21 -> {22}; 21 -> {22};
22 -> {30 23}; 22 -> {23};
23 -> {24}; 23 -> {24};
24 -> {25}; 24 -> {26 25};
25 -> {26}; 25 -> {32};
26 -> {27}; 26 -> {27};
27 -> {28}; 27 -> {28};
28 -> {29}; 28 -> {29};
29 -> {36}; 29 -> {30};
30 -> {31}; 30 -> {31};
31 -> {32}; 31 -> {32};
32 -> {48}; 32 -> {33};
32 -> {33} [style=dotted]; 33 -> {34};
33 -> {34} [style=dotted];
34 -> {35} [style=dotted];
35 -> {36} [style=dotted];
36 -> {37};
37 -> {38};
38 -> {40 39};
39 -> {46};
40 -> {41};
41 -> {42};
42 -> {43};
43 -> {44};
44 -> {45};
45 -> {46};
46 -> {47};
47 -> {48};
} }
@@ -8,15 +8,7 @@ FILE: smartcastFromArgument.kt
} }
public final fun test(a: R|kotlin/Any|): R|kotlin/Unit| { public final fun test(a: R|kotlin/Any|): R|kotlin/Unit| {
when () { when () {
R|/takeA|(when (lval <elvis>: R|A?| = (R|<local>/a| as? R|A|)) { R|/takeA|((R|<local>/a| as? R|A|) ?: ^test Unit) -> {
==($subj$, Null(null)) -> {
^test Unit
}
else -> {
R|<local>/<elvis>|
}
}
) -> {
R|<local>/a|.R|/A.foo|() R|<local>/a|.R|/A.foo|()
} }
} }
File diff suppressed because it is too large Load Diff
@@ -86,15 +86,7 @@ FILE: nullability.kt
R|<local>/x|.<Inapplicable(WRONG_RECEIVER): [/A.foo]>#() R|<local>/x|.<Inapplicable(WRONG_RECEIVER): [/A.foo]>#()
} }
public final fun test_3(x: R|A?|): R|kotlin/Unit| { public final fun test_3(x: R|A?|): R|kotlin/Unit| {
when (lval <elvis>: R|A?| = R|<local>/x|) { R|<local>/x| ?: ^test_3 Unit
==($subj$, Null(null)) -> {
^test_3 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/x|.R|/A.foo|() R|<local>/x|.R|/A.foo|()
} }
public final fun test_4(x: R|A?|): R|kotlin/Unit| { public final fun test_4(x: R|A?|): R|kotlin/Unit| {
@@ -117,15 +109,7 @@ FILE: nullability.kt
} }
public final fun test_6(q: R|Q?|): R|kotlin/Unit| { public final fun test_6(q: R|Q?|): R|kotlin/Unit| {
when (lval <elvis>: R|kotlin/Int?| = R|<local>/q|?.{ $subj$.R|/Q.data| }?.{ $subj$.R|/MyData.s| }?.{ $subj$.R|kotlin/Int.inc|() }) { R|<local>/q|?.{ $subj$.R|/Q.data| }?.{ $subj$.R|/MyData.s| }?.{ $subj$.R|kotlin/Int.inc|() } ?: ^test_6 Unit
==($subj$, Null(null)) -> {
^test_6 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/q|.R|/Q.data| R|<local>/q|.R|/Q.data|
R|<local>/q|.R|/Q.data|.<Inapplicable(WRONG_RECEIVER): [/MyData.s]># R|<local>/q|.R|/Q.data|.<Inapplicable(WRONG_RECEIVER): [/MyData.s]>#
R|<local>/q|.R|/Q.data|.<Inapplicable(WRONG_RECEIVER): [/MyData.s]>#.<Unresolved name: inc>#() R|<local>/q|.R|/Q.data|.<Inapplicable(WRONG_RECEIVER): [/MyData.s]>#.<Unresolved name: inc>#()
@@ -198,164 +198,173 @@ digraph assignSafeCall_kt {
subgraph cluster_19 { subgraph cluster_19 {
color=blue color=blue
68 [label="Enter block"]; 68 [label="Enter block"];
subgraph cluster_20 { 69 [label="Access variable R|<local>/x|"];
color=blue 70 [label="Type operator: (R|<local>/x| as? R|A|)"];
69 [label="Enter when"]; 71 [label="Exit lhs of ?:"];
70 [label="Access variable R|<local>/x|"]; 72 [label="Enter rhs of ?:"];
71 [label="Type operator: (R|<local>/x| as? R|A|)"]; 73 [label="Jump: ^test_3 Unit"];
72 [label="Variable declaration: lval <elvis>: R|A?|"]; 74 [label="Stub" style="filled" fillcolor=gray];
subgraph cluster_21 { 75 [label="Lhs of ?: is not null"];
color=blue 76 [label="Exit ?:"];
73 [label="Enter when branch condition "]; 77 [label="Variable declaration: lval a: R|A|"];
74 [label="Const: Null(null)"]; 78 [label="Access variable R|<local>/a|"];
75 [label="Operator =="]; 79 [label="Function call: R|<local>/a|.R|/A.foo|()"];
76 [label="Exit when branch condition"]; 80 [label="Access variable R|<local>/x|"];
} 81 [label="Function call: R|<local>/x|.R|/A.foo|()"];
subgraph cluster_22 { 82 [label="Exit block"];
color=blue
77 [label="Enter when branch condition else"];
78 [label="Exit when branch condition"];
}
79 [label="Enter when branch result"];
subgraph cluster_23 {
color=blue
80 [label="Enter block"];
81 [label="Access variable R|<local>/<elvis>|"];
82 [label="Exit block"];
}
83 [label="Exit when branch result"];
84 [label="Enter when branch result"];
subgraph cluster_24 {
color=blue
85 [label="Enter block"];
86 [label="Jump: ^test_3 Unit"];
87 [label="Stub" style="filled" fillcolor=gray];
88 [label="Exit block" style="filled" fillcolor=gray];
}
89 [label="Exit when branch result" style="filled" fillcolor=gray];
90 [label="Exit when"];
}
91 [label="Variable declaration: lval a: R|A|"];
92 [label="Access variable R|<local>/a|"];
93 [label="Function call: R|<local>/a|.R|/A.foo|()"];
94 [label="Access variable R|<local>/x|"];
95 [label="Function call: R|<local>/x|.R|/A.foo|()"];
96 [label="Exit block"];
} }
97 [label="Exit function test_3" style="filled" fillcolor=red]; 83 [label="Exit function test_3" style="filled" fillcolor=red];
} }
67 -> {68}; 67 -> {68};
68 -> {69}; 68 -> {69};
69 -> {70}; 69 -> {70};
70 -> {71}; 70 -> {71};
71 -> {72}; 71 -> {75 72};
72 -> {73}; 72 -> {73};
73 -> {74}; 73 -> {83};
74 -> {75}; 73 -> {74} [style=dotted];
74 -> {76} [style=dotted];
75 -> {76}; 75 -> {76};
76 -> {84 77}; 76 -> {77};
77 -> {78}; 77 -> {78};
78 -> {79}; 78 -> {79};
79 -> {80}; 79 -> {80};
80 -> {81}; 80 -> {81};
81 -> {82}; 81 -> {82};
82 -> {83}; 82 -> {83};
83 -> {90};
84 -> {85}; subgraph cluster_20 {
85 -> {86}; color=red
86 -> {97}; 84 [label="Enter class B" style="filled" fillcolor=red];
86 -> {87} [style=dotted]; 85 [label="Exit class B" style="filled" fillcolor=red];
87 -> {88} [style=dotted]; }
88 -> {89} [style=dotted]; 84 -> {85} [color=green];
89 -> {90} [style=dotted];
subgraph cluster_21 {
color=red
86 [label="Enter function foo" style="filled" fillcolor=red];
87 [label="Exit function foo" style="filled" fillcolor=red];
}
86 -> {87};
subgraph cluster_22 {
color=red
88 [label="Enter function getter" style="filled" fillcolor=red];
89 [label="Exit function getter" style="filled" fillcolor=red];
}
88 -> {89};
subgraph cluster_23 {
color=red
90 [label="Enter function bar" style="filled" fillcolor=red];
91 [label="Exit function bar" style="filled" fillcolor=red];
}
90 -> {91}; 90 -> {91};
91 -> {92};
subgraph cluster_24 {
color=red
92 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_25 {
color=blue
93 [label="Enter block"];
94 [label="Access variable R|<local>/a|"];
95 [label="Enter safe call"];
96 [label="Access variable R|/B.x|"];
97 [label="Exit safe call"];
98 [label="Variable declaration: lval x: R|kotlin/Int?|"];
subgraph cluster_26 {
color=blue
99 [label="Enter when"];
subgraph cluster_27 {
color=blue
100 [label="Enter when branch condition "];
101 [label="Access variable R|<local>/x|"];
102 [label="Const: Null(null)"];
103 [label="Operator !="];
104 [label="Exit when branch condition"];
}
105 [label="Synthetic else branch"];
106 [label="Enter when branch result"];
subgraph cluster_28 {
color=blue
107 [label="Enter block"];
108 [label="Access variable R|<local>/a|"];
109 [label="Function call: R|<local>/a|.R|/B.bar|()"];
110 [label="Exit block"];
}
111 [label="Exit when branch result"];
112 [label="Exit when"];
}
113 [label="Exit block"];
}
114 [label="Exit function test_1" style="filled" fillcolor=red];
}
92 -> {93}; 92 -> {93};
93 -> {94}; 93 -> {94};
94 -> {95}; 94 -> {95 97};
95 -> {96}; 95 -> {96};
96 -> {97}; 96 -> {97};
97 -> {98};
subgraph cluster_25 { 98 -> {99};
color=red 99 -> {100};
98 [label="Enter class B" style="filled" fillcolor=red];
99 [label="Exit class B" style="filled" fillcolor=red];
}
98 -> {99} [color=green];
subgraph cluster_26 {
color=red
100 [label="Enter function foo" style="filled" fillcolor=red];
101 [label="Exit function foo" style="filled" fillcolor=red];
}
100 -> {101}; 100 -> {101};
101 -> {102};
subgraph cluster_27 {
color=red
102 [label="Enter function getter" style="filled" fillcolor=red];
103 [label="Exit function getter" style="filled" fillcolor=red];
}
102 -> {103}; 102 -> {103};
103 -> {104};
subgraph cluster_28 { 104 -> {106 105};
color=red 105 -> {112};
104 [label="Enter function bar" style="filled" fillcolor=red];
105 [label="Exit function bar" style="filled" fillcolor=red];
}
104 -> {105};
subgraph cluster_29 {
color=red
106 [label="Enter function test_1" style="filled" fillcolor=red];
subgraph cluster_30 {
color=blue
107 [label="Enter block"];
108 [label="Access variable R|<local>/a|"];
109 [label="Enter safe call"];
110 [label="Access variable R|/B.x|"];
111 [label="Exit safe call"];
112 [label="Variable declaration: lval x: R|kotlin/Int?|"];
subgraph cluster_31 {
color=blue
113 [label="Enter when"];
subgraph cluster_32 {
color=blue
114 [label="Enter when branch condition "];
115 [label="Access variable R|<local>/x|"];
116 [label="Const: Null(null)"];
117 [label="Operator !="];
118 [label="Exit when branch condition"];
}
119 [label="Synthetic else branch"];
120 [label="Enter when branch result"];
subgraph cluster_33 {
color=blue
121 [label="Enter block"];
122 [label="Access variable R|<local>/a|"];
123 [label="Function call: R|<local>/a|.R|/B.bar|()"];
124 [label="Exit block"];
}
125 [label="Exit when branch result"];
126 [label="Exit when"];
}
127 [label="Exit block"];
}
128 [label="Exit function test_1" style="filled" fillcolor=red];
}
106 -> {107}; 106 -> {107};
107 -> {108}; 107 -> {108};
108 -> {109 111}; 108 -> {109};
109 -> {110}; 109 -> {110};
110 -> {111}; 110 -> {111};
111 -> {112}; 111 -> {112};
112 -> {113}; 112 -> {113};
113 -> {114}; 113 -> {114};
114 -> {115};
subgraph cluster_29 {
color=red
115 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_30 {
color=blue
116 [label="Enter block"];
117 [label="Access variable R|<local>/a|"];
118 [label="Enter safe call"];
119 [label="Function call: $subj$.R|/B.foo|()"];
120 [label="Exit safe call"];
121 [label="Variable declaration: lval x: R|kotlin/Int?|"];
subgraph cluster_31 {
color=blue
122 [label="Enter when"];
subgraph cluster_32 {
color=blue
123 [label="Enter when branch condition "];
124 [label="Access variable R|<local>/x|"];
125 [label="Const: Null(null)"];
126 [label="Operator !="];
127 [label="Exit when branch condition"];
}
128 [label="Synthetic else branch"];
129 [label="Enter when branch result"];
subgraph cluster_33 {
color=blue
130 [label="Enter block"];
131 [label="Access variable R|<local>/a|"];
132 [label="Function call: R|<local>/a|.R|/B.bar|()"];
133 [label="Exit block"];
}
134 [label="Exit when branch result"];
135 [label="Exit when"];
}
136 [label="Exit block"];
}
137 [label="Exit function test_2" style="filled" fillcolor=red];
}
115 -> {116}; 115 -> {116};
116 -> {117}; 116 -> {117};
117 -> {118}; 117 -> {118 120};
118 -> {120 119}; 118 -> {119};
119 -> {126}; 119 -> {120};
120 -> {121}; 120 -> {121};
121 -> {122}; 121 -> {122};
122 -> {123}; 122 -> {123};
@@ -363,151 +372,56 @@ digraph assignSafeCall_kt {
124 -> {125}; 124 -> {125};
125 -> {126}; 125 -> {126};
126 -> {127}; 126 -> {127};
127 -> {128}; 127 -> {129 128};
128 -> {135};
subgraph cluster_34 {
color=red
129 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_35 {
color=blue
130 [label="Enter block"];
131 [label="Access variable R|<local>/a|"];
132 [label="Enter safe call"];
133 [label="Function call: $subj$.R|/B.foo|()"];
134 [label="Exit safe call"];
135 [label="Variable declaration: lval x: R|kotlin/Int?|"];
subgraph cluster_36 {
color=blue
136 [label="Enter when"];
subgraph cluster_37 {
color=blue
137 [label="Enter when branch condition "];
138 [label="Access variable R|<local>/x|"];
139 [label="Const: Null(null)"];
140 [label="Operator !="];
141 [label="Exit when branch condition"];
}
142 [label="Synthetic else branch"];
143 [label="Enter when branch result"];
subgraph cluster_38 {
color=blue
144 [label="Enter block"];
145 [label="Access variable R|<local>/a|"];
146 [label="Function call: R|<local>/a|.R|/B.bar|()"];
147 [label="Exit block"];
}
148 [label="Exit when branch result"];
149 [label="Exit when"];
}
150 [label="Exit block"];
}
151 [label="Exit function test_2" style="filled" fillcolor=red];
}
129 -> {130}; 129 -> {130};
130 -> {131}; 130 -> {131};
131 -> {132 134}; 131 -> {132};
132 -> {133}; 132 -> {133};
133 -> {134}; 133 -> {134};
134 -> {135}; 134 -> {135};
135 -> {136}; 135 -> {136};
136 -> {137}; 136 -> {137};
137 -> {138};
subgraph cluster_34 {
color=red
138 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_35 {
color=blue
139 [label="Enter block"];
140 [label="Access variable R|<local>/x|"];
141 [label="Type operator: (R|<local>/x| as? R|B|)"];
142 [label="Exit lhs of ?:"];
143 [label="Enter rhs of ?:"];
144 [label="Jump: ^test_3 Unit"];
145 [label="Stub" style="filled" fillcolor=gray];
146 [label="Lhs of ?: is not null"];
147 [label="Exit ?:"];
148 [label="Variable declaration: lval a: R|B|"];
149 [label="Access variable R|<local>/a|"];
150 [label="Function call: R|<local>/a|.R|/B.foo|()"];
151 [label="Access variable R|<local>/x|"];
152 [label="Function call: R|<local>/x|.R|/B.foo|()"];
153 [label="Exit block"];
}
154 [label="Exit function test_3" style="filled" fillcolor=red];
}
138 -> {139}; 138 -> {139};
139 -> {140}; 139 -> {140};
140 -> {141}; 140 -> {141};
141 -> {143 142}; 141 -> {142};
142 -> {149}; 142 -> {146 143};
143 -> {144}; 143 -> {144};
144 -> {145}; 144 -> {154};
145 -> {146}; 144 -> {145} [style=dotted];
145 -> {147} [style=dotted];
146 -> {147}; 146 -> {147};
147 -> {148}; 147 -> {148};
148 -> {149}; 148 -> {149};
149 -> {150}; 149 -> {150};
150 -> {151}; 150 -> {151};
151 -> {152};
subgraph cluster_39 {
color=red
152 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_40 {
color=blue
153 [label="Enter block"];
subgraph cluster_41 {
color=blue
154 [label="Enter when"];
155 [label="Access variable R|<local>/x|"];
156 [label="Type operator: (R|<local>/x| as? R|B|)"];
157 [label="Variable declaration: lval <elvis>: R|B?|"];
subgraph cluster_42 {
color=blue
158 [label="Enter when branch condition "];
159 [label="Const: Null(null)"];
160 [label="Operator =="];
161 [label="Exit when branch condition"];
}
subgraph cluster_43 {
color=blue
162 [label="Enter when branch condition else"];
163 [label="Exit when branch condition"];
}
164 [label="Enter when branch result"];
subgraph cluster_44 {
color=blue
165 [label="Enter block"];
166 [label="Access variable R|<local>/<elvis>|"];
167 [label="Exit block"];
}
168 [label="Exit when branch result"];
169 [label="Enter when branch result"];
subgraph cluster_45 {
color=blue
170 [label="Enter block"];
171 [label="Jump: ^test_3 Unit"];
172 [label="Stub" style="filled" fillcolor=gray];
173 [label="Exit block" style="filled" fillcolor=gray];
}
174 [label="Exit when branch result" style="filled" fillcolor=gray];
175 [label="Exit when"];
}
176 [label="Variable declaration: lval a: R|B|"];
177 [label="Access variable R|<local>/a|"];
178 [label="Function call: R|<local>/a|.R|/B.foo|()"];
179 [label="Access variable R|<local>/x|"];
180 [label="Function call: R|<local>/x|.R|/B.foo|()"];
181 [label="Exit block"];
}
182 [label="Exit function test_3" style="filled" fillcolor=red];
}
152 -> {153}; 152 -> {153};
153 -> {154}; 153 -> {154};
154 -> {155};
155 -> {156};
156 -> {157};
157 -> {158};
158 -> {159};
159 -> {160};
160 -> {161};
161 -> {169 162};
162 -> {163};
163 -> {164};
164 -> {165};
165 -> {166};
166 -> {167};
167 -> {168};
168 -> {175};
169 -> {170};
170 -> {171};
171 -> {182};
171 -> {172} [style=dotted];
172 -> {173} [style=dotted];
173 -> {174} [style=dotted];
174 -> {175} [style=dotted];
175 -> {176};
176 -> {177};
177 -> {178};
178 -> {179};
179 -> {180};
180 -> {181};
181 -> {182};
} }
@@ -34,15 +34,7 @@ FILE: assignSafeCall.kt
} }
public final fun test_3(x: R|kotlin/Any?|): R|kotlin/Unit| { public final fun test_3(x: R|kotlin/Any?|): R|kotlin/Unit| {
lval a: R|A| = when (lval <elvis>: R|A?| = (R|<local>/x| as? R|A|)) { lval a: R|A| = (R|<local>/x| as? R|A|) ?: ^test_3 Unit
==($subj$, Null(null)) -> {
^test_3 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/a|.R|/A.foo|() R|<local>/a|.R|/A.foo|()
R|<local>/x|.R|/A.foo|() R|<local>/x|.R|/A.foo|()
} }
@@ -74,15 +66,7 @@ FILE: assignSafeCall.kt
} }
public final fun test_3(x: R|kotlin/Any?|): R|kotlin/Unit| { public final fun test_3(x: R|kotlin/Any?|): R|kotlin/Unit| {
lval a: R|B| = when (lval <elvis>: R|B?| = (R|<local>/x| as? R|B|)) { lval a: R|B| = (R|<local>/x| as? R|B|) ?: ^test_3 Unit
==($subj$, Null(null)) -> {
^test_3 Unit
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/a|.R|/B.foo|() R|<local>/a|.R|/B.foo|()
R|<local>/x|.R|/B.foo|() R|<local>/x|.R|/B.foo|()
} }
@@ -0,0 +1,18 @@
// ISSUE: KT-39074
interface A
interface B : A {
fun bar()
}
fun <K : A> materialize(): K? = null!!
fun foo(b: B, cond: Boolean) {
val x = // inferred as A
if (cond)
b
else
materialize() ?: return
x.bar()
}
@@ -6,25 +6,17 @@ FILE: ifElvisReturn.kt
} }
public final fun <K : R|A|> materialize(): R|K?| { public final fun <K : R|A|> materialize(): R|K?| {
^materialize R|kotlin/TODO|() ^materialize Null(null)!!
} }
public final fun foo(b: R|B|): R|kotlin/Unit| { public final fun foo(b: R|B|, cond: R|kotlin/Boolean|): R|kotlin/Unit| {
lval x: R|A| = when () { lval x: R|B| = when () {
CMP(>, R|<local>/b|.R|kotlin/Any.hashCode|().R|kotlin/Int.compareTo|(Int(0))) -> { R|<local>/cond| -> {
R|<local>/b| R|<local>/b|
} }
else -> { else -> {
when (lval <elvis>: R|A?| = R|/materialize|<R|A|>()) { R|/materialize|<R|kotlin/Nothing|>() ?: ^foo Unit
==($subj$, Null(null)) -> {
^foo Unit
}
else -> {
R|<local>/<elvis>|
}
}
} }
} }
R|<local>/x|.<Unresolved name: bar>#() R|<local>/x|.R|/B.bar|()
} }
@@ -1,15 +1,7 @@
FILE: MapCompute.kt FILE: MapCompute.kt
public final fun <D> R|kotlin/collections/MutableMap<kotlin/String, kotlin/collections/MutableSet<D>>|.initAndAdd(key: R|kotlin/String|, value: R|D|): R|kotlin/Unit| { public final fun <D> R|kotlin/collections/MutableMap<kotlin/String, kotlin/collections/MutableSet<D>>|.initAndAdd(key: R|kotlin/String|, value: R|D|): R|kotlin/Unit| {
this@R|/initAndAdd|.R|FakeOverride<kotlin/collections/MutableMap.compute: R|kotlin/collections/MutableSet<D>?|>|(R|<local>/key|, <L> = compute@fun <anonymous>(_: R|ft<kotlin/String, kotlin/String?>!|, maybeValues: R|ft<kotlin/collections/MutableSet<D>, kotlin/collections/MutableSet<D>?>!|): R|ft<kotlin/collections/MutableSet<D>, kotlin/collections/MutableSet<D>?>!| { this@R|/initAndAdd|.R|FakeOverride<kotlin/collections/MutableMap.compute: R|kotlin/collections/MutableSet<D>?|>|(R|<local>/key|, <L> = compute@fun <anonymous>(_: R|ft<kotlin/String, kotlin/String?>!|, maybeValues: R|ft<kotlin/collections/MutableSet<D>, kotlin/collections/MutableSet<D>?>!|): R|ft<kotlin/collections/MutableSet<D>, kotlin/collections/MutableSet<D>?>!| {
lval setOfValues: R|kotlin/collections/MutableSet<D>| = when (lval <elvis>: R|ft<kotlin/collections/MutableSet<D>, kotlin/collections/MutableSet<D>?>!| = R|<local>/maybeValues|) { lval setOfValues: R|kotlin/collections/MutableSet<D>| = R|<local>/maybeValues| ?: R|kotlin/collections/mutableSetOf|<R|D|>()
==($subj$, Null(null)) -> {
R|kotlin/collections/mutableSetOf|<R|D|>()
}
else -> {
R|<local>/<elvis>|
}
}
R|<local>/setOfValues|.R|FakeOverride<kotlin/collections/MutableSet.add: R|kotlin/Boolean|>|(R|<local>/value|) R|<local>/setOfValues|.R|FakeOverride<kotlin/collections/MutableSet.add: R|kotlin/Boolean|>|(R|<local>/value|)
^ R|<local>/setOfValues| ^ R|<local>/setOfValues|
} }
@@ -1484,6 +1484,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaAsReturnStatementOfLambda.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaAsReturnStatementOfLambda.kt");
} }
@TestMetadata("lambdaInElvis.kt")
public void testLambdaInElvis() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaInElvis.kt");
}
@TestMetadata("nestedExtensionFunctionType.kt") @TestMetadata("nestedExtensionFunctionType.kt")
public void testNestedExtensionFunctionType() throws Exception { public void testNestedExtensionFunctionType() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.kt");
@@ -1484,6 +1484,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaAsReturnStatementOfLambda.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaAsReturnStatementOfLambda.kt");
} }
@TestMetadata("lambdaInElvis.kt")
public void testLambdaInElvis() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/lambdaInElvis.kt");
}
@TestMetadata("nestedExtensionFunctionType.kt") @TestMetadata("nestedExtensionFunctionType.kt")
public void testNestedExtensionFunctionType() throws Exception { public void testNestedExtensionFunctionType() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.kt");
@@ -711,6 +711,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic
public void testFlexibleTypeInSystem() throws Exception { public void testFlexibleTypeInSystem() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.kt"); runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/flexibleTypeInSystem.kt");
} }
@TestMetadata("ifElvisReturn.kt")
public void testIfElvisReturn() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/ifElvisReturn.kt");
}
} }
@TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k") @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k")
@@ -9,20 +9,28 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
object SyntheticCallableId { object SyntheticCallableId {
private val syntheticPackageName: FqName = FqName("_synthetic")
val WHEN = CallableId( val WHEN = CallableId(
FqName("_synthetic"), syntheticPackageName,
Name.identifier("WHEN_CALL") Name.identifier("WHEN_CALL")
) )
val TRY = CallableId( val TRY = CallableId(
FqName("_synthetic"), syntheticPackageName,
Name.identifier("TRY_CALL") Name.identifier("TRY_CALL")
) )
val CHECK_NOT_NULL = CallableId( val CHECK_NOT_NULL = CallableId(
FqName("_synthetic"), syntheticPackageName,
Name.identifier("CHECK_NOT_NULL_CALL") Name.identifier("CHECK_NOT_NULL_CALL")
) )
val ELVIS_NOT_NULL = CallableId(
syntheticPackageName,
Name.identifier("ELVIS_CALL")
)
val ID = CallableId( val ID = CallableId(
FqName("_synthetic"), syntheticPackageName,
Name.identifier("ID_CALL") Name.identifier("ID_CALL")
) )
} }
@@ -1359,6 +1359,12 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
+"!!" +"!!"
} }
private fun FlowContent.generate(elvisCall: FirElvisCall) {
generate(elvisCall.lhs)
+" ?: "
generate(elvisCall.rhs)
}
@Suppress("UNUSED_PARAMETER") @Suppress("UNUSED_PARAMETER")
private fun FlowContent.generate(elseIfTrueCondition: FirElseIfTrueCondition) { private fun FlowContent.generate(elseIfTrueCondition: FirElseIfTrueCondition) {
keyword("else") keyword("else")
@@ -1563,6 +1569,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
is FirOperatorCall -> generate(expression) is FirOperatorCall -> generate(expression)
is FirBinaryLogicExpression -> generate(expression) is FirBinaryLogicExpression -> generate(expression)
is FirCheckNotNullCall -> generate(expression) is FirCheckNotNullCall -> generate(expression)
is FirElvisCall -> generate(expression)
is FirVarargArgumentsExpression -> generate(expression) is FirVarargArgumentsExpression -> generate(expression)
is FirResolvedReifiedParameterReference -> generate(expression) is FirResolvedReifiedParameterReference -> generate(expression)
is FirComparisonExpression -> generate(expression) is FirComparisonExpression -> generate(expression)
@@ -141,45 +141,12 @@ fun IElementType.toFirOperation(): FirOperation =
} }
fun FirExpression.generateNotNullOrOther( fun FirExpression.generateNotNullOrOther(
session: FirSession, other: FirExpression, caseId: String, baseSource: FirSourceElement?, other: FirExpression, baseSource: FirSourceElement?,
): FirWhenExpression { ): FirElvisCall {
val subjectName = Name.special("<$caseId>") return buildElvisCall {
val subjectSource = baseSource?.withKind(FirFakeSourceElementKind.WhenGeneratedSubject)
val subjectVariable = generateTemporaryVariable(session, subjectSource, subjectName, this)
@OptIn(FirContractViolation::class)
val ref = FirExpressionRef<FirWhenExpression>()
val subjectExpression = buildWhenSubjectExpression {
source = subjectSource
whenRef = ref
}
return buildWhenExpression {
source = baseSource source = baseSource
this.subject = this@generateNotNullOrOther lhs = this@generateNotNullOrOther
this.subjectVariable = subjectVariable rhs = other
branches += buildWhenBranch {
val branchSource = baseSource?.withKind(FirFakeSourceElementKind.WhenCondition)
source = branchSource
condition = buildOperatorCall {
source = branchSource
operation = FirOperation.EQ
argumentList = buildBinaryArgumentList(
subjectExpression, buildConstExpression(branchSource, FirConstKind.Null, null)
)
}
result = buildSingleExpressionBlock(other)
}
branches += buildWhenBranch {
val otherSource = other.source?.withKind(FirFakeSourceElementKind.WhenCondition)
source = otherSource
condition = buildElseIfTrueCondition {
source = otherSource
}
result = buildSingleExpressionBlock(generateResolvedAccessExpression(otherSource, subjectVariable))
}
}.also {
ref.bind(it)
} }
} }
@@ -246,7 +246,7 @@ class ExpressionsConverter(
when (operationToken) { when (operationToken) {
ELVIS -> ELVIS ->
return leftArgAsFir.generateNotNullOrOther(baseSession, rightArgAsFir, "elvis", baseSource) return leftArgAsFir.generateNotNullOrOther(rightArgAsFir, baseSource)
ANDAND, OROR -> ANDAND, OROR ->
return leftArgAsFir.generateLazyLogicalOperation(rightArgAsFir, operationToken == ANDAND, baseSource) return leftArgAsFir.generateLazyLogicalOperation(rightArgAsFir, operationToken == ANDAND, baseSource)
in OperatorConventions.IN_OPERATIONS -> in OperatorConventions.IN_OPERATIONS ->
@@ -1554,7 +1554,7 @@ class RawFirBuilder(
when (operationToken) { when (operationToken) {
ELVIS -> ELVIS ->
return leftArgument.generateNotNullOrOther(baseSession, rightArgument, "elvis", source) return leftArgument.generateNotNullOrOther(rightArgument, source)
ANDAND, OROR -> ANDAND, OROR ->
return leftArgument.generateLazyLogicalOperation(rightArgument, operationToken == ANDAND, source) return leftArgument.generateLazyLogicalOperation(rightArgument, operationToken == ANDAND, source)
in OperatorConventions.IN_OPERATIONS -> in OperatorConventions.IN_OPERATIONS ->
@@ -1,14 +1,6 @@
FILE: nullability.kt FILE: nullability.kt
public? final? fun orFourtyTwo(arg: Int?): <implicit> { public? final? fun orFourtyTwo(arg: Int?): <implicit> {
^orFourtyTwo when (lval <elvis>: <implicit> = arg#) { ^orFourtyTwo arg# ?: IntegerLiteral(42)
==($subj$, Null(null)) -> {
IntegerLiteral(42)
}
else -> {
R|<local>/<elvis>|
}
}
} }
public? final? fun bang(arg: Int?): <implicit> { public? final? fun bang(arg: Int?): <implicit> {
^bang arg#!! ^bang arg#!!
@@ -42,7 +42,7 @@ fun Candidate.resolveArgumentExpression(
isDispatch: Boolean isDispatch: Boolean
) { ) {
when (argument) { when (argument) {
is FirFunctionCall, is FirWhenExpression, is FirTryExpression, is FirCheckNotNullCall -> resolveSubCallArgument( is FirFunctionCall, is FirWhenExpression, is FirTryExpression, is FirCheckNotNullCall, is FirElvisCall -> resolveSubCallArgument(
csBuilder, csBuilder,
argument as FirResolvable, argument as FirResolvable,
expectedType, expectedType,
@@ -116,7 +116,8 @@ fun PostponedArgumentsAnalyzer.Context.addSubsystemFromExpression(statement: Fir
is FirWhenExpression, is FirWhenExpression,
is FirTryExpression, is FirTryExpression,
is FirCheckNotNullCall, is FirCheckNotNullCall,
is FirCallableReferenceAccess is FirCallableReferenceAccess,
is FirElvisCall
-> (statement as FirResolvable).candidate()?.let { addOtherSystem(it.system.asReadOnlyStorage()) } -> (statement as FirResolvable).candidate()?.let { addOtherSystem(it.system.asReadOnlyStorage()) }
is FirSafeCallExpression -> addSubsystemFromExpression(statement.regularQualifiedAccess) is FirSafeCallExpression -> addSubsystemFromExpression(statement.regularQualifiedAccess)
@@ -1015,6 +1015,37 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
graphBuilder.exitContractDescription() graphBuilder.exitContractDescription()
} }
// ----------------------------------- Elvis -----------------------------------
fun exitElvisLhs(elvisCall: FirElvisCall) {
val (lhsExitNode, lhsIsNotNullNode, rhsEnterNode) = graphBuilder.exitElvisLhs(elvisCall)
lhsExitNode.mergeIncomingFlow()
val flow = lhsExitNode.flow
val lhsVariable = variableStorage.getOrCreateVariable(flow, elvisCall.lhs)
rhsEnterNode.flow = logicSystem.approveStatementsInsideFlow(
flow,
lhsVariable eq null,
shouldForkFlow = true,
shouldRemoveSynthetics = false
)
lhsIsNotNullNode.flow = logicSystem.approveStatementsInsideFlow(
flow,
lhsVariable notEq null,
shouldForkFlow = true,
shouldRemoveSynthetics = false
).also {
if (lhsVariable.isReal()) {
it.addTypeStatement(lhsVariable typeEq any)
}
}
}
fun exitElvis(callCompleted: Boolean) {
val (elvisExitNode, unionNode) = graphBuilder.exitElvis(callCompleted)
elvisExitNode.mergeIncomingFlow()
unionNode?.let { unionFlowFromArguments(it) }
}
// ------------------------------------------------------ Utils ------------------------------------------------------ // ------------------------------------------------------ Utils ------------------------------------------------------
private var CFGNode<*>.flow: FLOW private var CFGNode<*>.flow: FLOW
@@ -601,6 +601,32 @@ class ExitSafeCallNode(owner: ControlFlowGraph, override val fir: FirSafeCallExp
} }
} }
// ----------------------------------- Elvis -----------------------------------
class ElvisLhsExitNode(owner: ControlFlowGraph, override val fir: FirElvisCall, level: Int, id: Int) : CFGNode<FirElvisCall>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitElvisLhsExitNode(this, data)
}
}
class ElvisLhsIsNotNullNode(owner: ControlFlowGraph, override val fir: FirElvisCall, level: Int, id: Int) : CFGNode<FirElvisCall>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitElvisLhsIsNotNullNode(this, data)
}
}
class ElvisRhsEnterNode(owner: ControlFlowGraph, override val fir: FirElvisCall, level: Int, id: Int) : CFGNode<FirElvisCall>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitElvisRhsEnterNode(this, data)
}
}
class ElvisExitNode(owner: ControlFlowGraph, override val fir: FirElvisCall, level: Int, id: Int) : AbstractBinaryExitNode<FirElvisCall>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitElvisExitNode(this, data)
}
}
// ----------------------------------- Other ----------------------------------- // ----------------------------------- Other -----------------------------------
class AnnotationEnterNode(owner: ControlFlowGraph, override val fir: FirAnnotationCall, level: Int, id: Int) : CFGNode<FirAnnotationCall>(owner, level, id), EnterNodeMarker { class AnnotationEnterNode(owner: ControlFlowGraph, override val fir: FirAnnotationCall, level: Int, id: Int) : CFGNode<FirAnnotationCall>(owner, level, id), EnterNodeMarker {
@@ -106,10 +106,15 @@ fun CFGNode<*>.render(): String =
is ContractDescriptionEnterNode -> "Enter contract description" is ContractDescriptionEnterNode -> "Enter contract description"
is AbstractBinaryExitNode -> throw IllegalStateException()
is EnterDefaultArgumentsNode -> "Enter default value of ${fir.name}" is EnterDefaultArgumentsNode -> "Enter default value of ${fir.name}"
is ExitDefaultArgumentsNode -> "Exit default value of ${fir.name}" is ExitDefaultArgumentsNode -> "Exit default value of ${fir.name}"
is ElvisLhsExitNode -> "Exit lhs of ?:"
is ElvisLhsIsNotNullNode -> "Lhs of ?: is not null"
is ElvisRhsEnterNode -> "Enter rhs of ?:"
is ElvisExitNode -> "Exit ?:"
is AbstractBinaryExitNode -> throw IllegalStateException()
}, },
) )
} }
@@ -91,6 +91,7 @@ class ControlFlowGraphBuilder {
private val initBlockExitNodes: Stack<InitBlockExitNode> = stackOf() private val initBlockExitNodes: Stack<InitBlockExitNode> = stackOf()
private val exitSafeCallNodes: Stack<ExitSafeCallNode> = stackOf() private val exitSafeCallNodes: Stack<ExitSafeCallNode> = stackOf()
private val exitElvisCallNodes: Stack<ElvisExitNode> = stackOf()
// ----------------------------------- API for node builders ----------------------------------- // ----------------------------------- API for node builders -----------------------------------
@@ -986,6 +987,37 @@ class ControlFlowGraphBuilder {
} }
} }
// ----------------------------------- Elvis -----------------------------------
fun exitElvisLhs(elvisCall: FirElvisCall): Triple<ElvisLhsExitNode, ElvisLhsIsNotNullNode, ElvisRhsEnterNode> {
val exitNode = createElvisExitNode(elvisCall).also {
exitElvisCallNodes.push(it)
}
val lhsExitNode = createElvisLhsExitNode(elvisCall).also {
popAndAddEdge(it)
}
val lhsIsNotNullNode = createElvisLhsIsNotNullNode(elvisCall).also {
addEdge(lhsExitNode, it)
addEdge(it, exitNode)
}
val rhsEnterNode = createElvisRhsEnterNode(elvisCall).also {
addEdge(lhsExitNode, it)
}
lastNodes.push(rhsEnterNode)
return Triple(lhsExitNode, lhsIsNotNullNode, rhsEnterNode)
}
fun exitElvis(callCompleted: Boolean): Pair<ElvisExitNode, UnionFunctionCallArgumentsNode?> {
val exitNode = exitElvisCallNodes.pop()
addNewSimpleNode(exitNode)
exitNode.updateDeadStatus()
val (_, unionNode) = processUnionOfArguments(exitNode, callCompleted)
return exitNode to unionNode
}
// ----------------------------------- Contract description ----------------------------------- // ----------------------------------- Contract description -----------------------------------
fun enterContractDescription(): CFGNode<*> { fun enterContractDescription(): CFGNode<*> {
@@ -125,6 +125,18 @@ fun ControlFlowGraphBuilder.createAnnotationExitNode(fir: FirAnnotationCall): An
fun ControlFlowGraphBuilder.createAnnotationEnterNode(fir: FirAnnotationCall): AnnotationEnterNode = fun ControlFlowGraphBuilder.createAnnotationEnterNode(fir: FirAnnotationCall): AnnotationEnterNode =
AnnotationEnterNode(currentGraph, fir, levelCounter, createId()) AnnotationEnterNode(currentGraph, fir, levelCounter, createId())
fun ControlFlowGraphBuilder.createElvisLhsIsNotNullNode(fir: FirElvisCall): ElvisLhsIsNotNullNode =
ElvisLhsIsNotNullNode(currentGraph, fir, levelCounter, createId())
fun ControlFlowGraphBuilder.createElvisRhsEnterNode(fir: FirElvisCall): ElvisRhsEnterNode =
ElvisRhsEnterNode(currentGraph, fir, levelCounter, createId())
fun ControlFlowGraphBuilder.createElvisLhsExitNode(fir: FirElvisCall): ElvisLhsExitNode =
ElvisLhsExitNode(currentGraph, fir, levelCounter, createId())
fun ControlFlowGraphBuilder.createElvisExitNode(fir: FirElvisCall): ElvisExitNode =
ElvisExitNode(currentGraph, fir, levelCounter, createId())
fun ControlFlowGraphBuilder.createVariableDeclarationNode(fir: FirProperty): VariableDeclarationNode = fun ControlFlowGraphBuilder.createVariableDeclarationNode(fir: FirProperty): VariableDeclarationNode =
VariableDeclarationNode(currentGraph, fir, levelCounter, createId()) VariableDeclarationNode(currentGraph, fir, levelCounter, createId())
@@ -307,6 +307,24 @@ abstract class ControlFlowGraphVisitor<out R, in D> {
return visitNode(node, data) return visitNode(node, data)
} }
// ----------------------------------- Elvis -----------------------------------
open fun visitElvisLhsExitNode(node: ElvisLhsExitNode, data: D): R {
return visitNode(node, data)
}
open fun visitElvisLhsIsNotNullNode(node: ElvisLhsIsNotNullNode, data: D): R {
return visitNode(node, data)
}
open fun visitElvisRhsEnterNode(node: ElvisRhsEnterNode, data: D): R {
return visitNode(node, data)
}
open fun visitElvisExitNode(node: ElvisExitNode, data: D): R {
return visitNode(node, data)
}
// ----------------------------------- Other ----------------------------------- // ----------------------------------- Other -----------------------------------
open fun visitAnnotationEnterNode(node: AnnotationEnterNode, data: D): R { open fun visitAnnotationEnterNode(node: AnnotationEnterNode, data: D): R {
@@ -292,6 +292,12 @@ fun FirStatement.processAllContainingCallCandidates(processBlocks: Boolean, proc
processCandidateIfApplicable(processor, processBlocks) processCandidateIfApplicable(processor, processBlocks)
this.arguments.forEach { it.processAllContainingCallCandidates(processBlocks, processor) } this.arguments.forEach { it.processAllContainingCallCandidates(processBlocks, processor) }
} }
is FirElvisCall -> {
processCandidateIfApplicable(processor, processBlocks)
lhs.processAllContainingCallCandidates(processBlocks, processor)
rhs.processAllContainingCallCandidates(processBlocks, processor)
}
} }
} }
@@ -423,14 +423,21 @@ class FirCallCompletionResultsWriterTransformer(
// Transformations for synthetic calls generated by FirSyntheticCallGenerator // Transformations for synthetic calls generated by FirSyntheticCallGenerator
override fun transformWhenExpression(whenExpression: FirWhenExpression, data: ExpectedArgumentType?) = override fun transformWhenExpression(whenExpression: FirWhenExpression, data: ExpectedArgumentType?): CompositeTransformResult<FirStatement> {
transformSyntheticCall(whenExpression, data) return transformSyntheticCall(whenExpression, data)
}
override fun transformTryExpression(tryExpression: FirTryExpression, data: ExpectedArgumentType?) = override fun transformTryExpression(tryExpression: FirTryExpression, data: ExpectedArgumentType?): CompositeTransformResult<FirStatement> {
transformSyntheticCall(tryExpression, data) return transformSyntheticCall(tryExpression, data)
}
override fun transformCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: ExpectedArgumentType?) = override fun transformCheckNotNullCall(checkNotNullCall: FirCheckNotNullCall, data: ExpectedArgumentType?): CompositeTransformResult<FirStatement> {
transformSyntheticCall(checkNotNullCall, data) return transformSyntheticCall(checkNotNullCall, data)
}
override fun transformElvisCall(elvisCall: FirElvisCall, data: ExpectedArgumentType?): CompositeTransformResult<FirStatement> {
return transformSyntheticCall(elvisCall, data)
}
private inline fun <reified D> transformSyntheticCall( private inline fun <reified D> transformSyntheticCall(
syntheticCall: D, syntheticCall: D,
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents
import org.jetbrains.kotlin.fir.resolve.calls.* import org.jetbrains.kotlin.fir.resolve.calls.*
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirAbstractBodyResolveTransformer
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.symbols.SyntheticCallableId import org.jetbrains.kotlin.fir.symbols.SyntheticCallableId
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
@@ -47,6 +48,7 @@ class FirSyntheticCallGenerator(
private val trySelectFunction: FirSimpleFunction = generateSyntheticSelectFunction(SyntheticCallableId.TRY) private val trySelectFunction: FirSimpleFunction = generateSyntheticSelectFunction(SyntheticCallableId.TRY)
private val idFunction: FirSimpleFunction = generateSyntheticSelectFunction(SyntheticCallableId.ID) private val idFunction: FirSimpleFunction = generateSyntheticSelectFunction(SyntheticCallableId.ID)
private val checkNotNullFunction: FirSimpleFunction = generateSyntheticCheckNotNullFunction() private val checkNotNullFunction: FirSimpleFunction = generateSyntheticCheckNotNullFunction()
private val elvisFunction: FirSimpleFunction = generateSyntheticElvisFunction()
fun generateCalleeForWhenExpression(whenExpression: FirWhenExpression): FirWhenExpression? { fun generateCalleeForWhenExpression(whenExpression: FirWhenExpression): FirWhenExpression? {
val stubReference = whenExpression.calleeReference val stubReference = whenExpression.calleeReference
@@ -101,6 +103,22 @@ class FirSyntheticCallGenerator(
return checkNotNullCall.transformCalleeReference(UpdateReference, reference) return checkNotNullCall.transformCalleeReference(UpdateReference, reference)
} }
fun generateCalleeForElvisCall(elvisCall: FirElvisCall): FirElvisCall? {
if (elvisCall.calleeReference !is FirStubReference) return null
val argumentList = buildArgumentList {
arguments += elvisCall.lhs
arguments += elvisCall.rhs
}
val reference = generateCalleeReferenceWithCandidate(
elvisFunction,
argumentList,
SyntheticCallableId.ELVIS_NOT_NULL.callableName
) ?: return null
return elvisCall.transformCalleeReference(UpdateReference, reference)
}
fun resolveCallableReferenceWithSyntheticOuterCall( fun resolveCallableReferenceWithSyntheticOuterCall(
callableReferenceAccess: FirCallableReferenceAccess, callableReferenceAccess: FirCallableReferenceAccess,
expectedTypeRef: FirTypeRef? expectedTypeRef: FirTypeRef?
@@ -225,6 +243,42 @@ class FirSyntheticCallGenerator(
}.build() }.build()
} }
private fun generateSyntheticElvisFunction(): FirSimpleFunction {
// Synthetic function signature:
// fun <K> checkNotNull(x: K?, y: K): @Exact K
//
// Note: The upper bound of `K` cannot be `Any` because of the following case:
// fun <X> test(a: X, b: X) = a ?: b
// `X` is not a subtype of `Any` and hence cannot satisfy `K` if it had an upper bound of `Any`.
val functionSymbol = FirSyntheticFunctionSymbol(SyntheticCallableId.ELVIS_NOT_NULL)
val (typeParameter, rightArgumentType) = generateSyntheticSelectTypeParameter()
val leftArgumentType = buildResolvedTypeRef {
type = rightArgumentType.coneTypeUnsafe<ConeKotlinType>().withNullability(ConeNullability.NULLABLE, session.typeContext)
}
val returnType = rightArgumentType.resolvedTypeFromPrototype(
rightArgumentType.type.withAttributes(
ConeAttributes.create(listOf(CompilerConeAttributes.Exact))
)
)
val typeArgument = buildTypeProjectionWithVariance {
typeRef = returnType
variance = Variance.INVARIANT
}
return generateMemberFunction(
functionSymbol,
SyntheticCallableId.ELVIS_NOT_NULL.callableName,
typeArgument.typeRef
).apply {
typeParameters += typeParameter
valueParameters += leftArgumentType.toValueParameter("x")
valueParameters += rightArgumentType.toValueParameter("y")
}.build()
}
private fun generateMemberFunction( private fun generateMemberFunction(
symbol: FirNamedFunctionSymbol, name: Name, returnType: FirTypeRef symbol: FirNamedFunctionSymbol, name: Name, returnType: FirTypeRef
): FirSimpleFunctionBuilder { ): FirSimpleFunctionBuilder {
@@ -304,6 +304,10 @@ open class FirBodyResolveTransformer(
return controlFlowStatementsTransformer.transformThrowExpression(throwExpression, data) return controlFlowStatementsTransformer.transformThrowExpression(throwExpression, data)
} }
override fun transformElvisCall(elvisCall: FirElvisCall, data: ResolutionMode): CompositeTransformResult<FirStatement> {
return controlFlowStatementsTransformer.transformElvisCall(elvisCall, data)
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
fun <D> FirElement.visitNoTransform(transformer: FirTransformer<D>, data: D) { fun <D> FirElement.visitNoTransform(transformer: FirTransformer<D>, data: D) {
@@ -208,4 +208,31 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirBodyResolveTran
dataFlowAnalyzer.exitThrowExceptionNode(it.single as FirThrowExpression) dataFlowAnalyzer.exitThrowExceptionNode(it.single as FirThrowExpression)
} }
} }
// ------------------------------- Elvis -------------------------------
override fun transformElvisCall(elvisCall: FirElvisCall, data: ResolutionMode): CompositeTransformResult<FirStatement> {
if (elvisCall.calleeReference is FirResolvedNamedReference) return elvisCall.compose()
elvisCall.transformAnnotations(transformer, data)
elvisCall.transformLhs(transformer, ResolutionMode.ContextDependent)
dataFlowAnalyzer.exitElvisLhs(elvisCall)
elvisCall.transformRhs(transformer, ResolutionMode.ContextDependent)
var callCompleted = false
val result = syntheticCallGenerator.generateCalleeForElvisCall(elvisCall)?.let {
val completionResult = callCompleter.completeCall(elvisCall, data.expectedType)
callCompleted = completionResult.callCompleted
completionResult.result
} ?: run {
elvisCall.resultType = buildErrorTypeRef {
diagnostic = ConeSimpleDiagnostic("Can't resolve ?: operator call", DiagnosticKind.InferenceError)
}
callCompleted = true
elvisCall
}
dataFlowAnalyzer.exitElvis(callCompleted)
return result.compose()
}
} }
@@ -6,14 +6,12 @@
package org.jetbrains.kotlin.fir.types package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.resolve.toSymbol import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
@@ -22,7 +20,6 @@ import org.jetbrains.kotlin.types.AbstractNullabilityChecker
import org.jetbrains.kotlin.types.AbstractStrictEqualityTypeChecker import org.jetbrains.kotlin.types.AbstractStrictEqualityTypeChecker
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
object ConeNullabilityChecker { object ConeNullabilityChecker {
fun isSubtypeOfAny(context: ConeTypeContext, type: ConeKotlinType): Boolean { fun isSubtypeOfAny(context: ConeTypeContext, type: ConeKotlinType): Boolean {
@@ -106,6 +103,21 @@ fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection
} }
} }
fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes): T {
if (this.attributes == attributes) {
return this
}
@Suppress("UNCHECKED_CAST")
return when (this) {
is ConeClassErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes)
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType.create(original.withAttributes(attributes))!!
is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes)
else -> error("Not supported: $this: ${this.render()}")
} as T
}
fun ConeTypeContext.hasNullableSuperType(type: ConeKotlinType): Boolean { fun ConeTypeContext.hasNullableSuperType(type: ConeKotlinType): Boolean {
if (type is ConeClassLikeType) return false if (type is ConeClassLikeType) return false
@@ -1022,6 +1022,12 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
print("!!") print("!!")
} }
override fun visitElvisCall(elvisCall: FirElvisCall) {
elvisCall.lhs.accept(this)
print(" ?: ")
elvisCall.rhs.accept(this)
}
override fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess) { override fun visitCallableReferenceAccess(callableReferenceAccess: FirCallableReferenceAccess) {
callableReferenceAccess.annotations.renderAnnotations() callableReferenceAccess.annotations.renderAnnotations()
callableReferenceAccess.explicitReceiver?.accept(this) callableReferenceAccess.explicitReceiver?.accept(this)
@@ -15,5 +15,5 @@ fun test(s: String?, silent: Boolean) {
throw Exception() throw Exception()
} }
s.<!INAPPLICABLE_CANDIDATE!>length<!> s.length
} }
@@ -42,7 +42,7 @@ fun test() {
inline fun <reified T : Any> reifiedNull(): T? = null inline fun <reified T : Any> reifiedNull(): T? = null
fun testFrom13648() { fun testFrom13648() {
<!INAPPLICABLE_CANDIDATE!>takeNotNull<!>(reifiedNull() ?: "") takeNotNull(reifiedNull() ?: "")
} }
fun bar() = <!UNRESOLVED_REFERENCE!>unresolved<!> fun bar() = <!UNRESOLVED_REFERENCE!>unresolved<!>
@@ -3,6 +3,6 @@
fun <T: Any> foo(f: (T) -> Unit): T? = null // T is used only as return type fun <T: Any> foo(f: (T) -> Unit): T? = null // T is used only as return type
fun test() { fun test() {
val x = foo { it checkType { <!INAPPLICABLE_CANDIDATE!>_<!><String>() }} ?: "" // foo() is inferred as foo<String>, which isn't very good val x = foo { it checkType { _<String>() }} ?: "" // foo() is inferred as foo<String>, which isn't very good
val y: Any = foo { it checkType { _<Any>() } } ?: "" // but for now it's fixed by specifying expected type val y: Any = foo { <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>it<!> checkType { <!INAPPLICABLE_CANDIDATE!>_<!><Any>() } } ?: "" // but for now it's fixed by specifying expected type
} }
@@ -6,7 +6,7 @@
fun <T: Any, K: Any> case_1(x: T?, y: K?) { fun <T: Any, K: Any> case_1(x: T?, y: K?) {
x as T x as T
y as K y as K
val z = <!DEBUG_INFO_EXPRESSION_TYPE("T?!! & T?")!>x<!> ?: <!DEBUG_INFO_EXPRESSION_TYPE("K?!!")!>y<!> val z = <!DEBUG_INFO_EXPRESSION_TYPE("T?!! & T?")!>x<!> ?: <!DEBUG_INFO_EXPRESSION_TYPE("K?!! & K?")!>y<!>
<!DEBUG_INFO_EXPRESSION_TYPE("T?!! & T?")!>x<!>.equals(10) <!DEBUG_INFO_EXPRESSION_TYPE("T?!! & T?")!>x<!>.equals(10)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>z<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>z<!>