[FIR] KT-37009: Fix loss of bound smart-cast due to synthetic removal
This commit is contained in:
+1
-1
@@ -552,7 +552,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
flow,
|
||||
variable notEq null,
|
||||
shouldFork,
|
||||
shouldRemoveSynthetics = true
|
||||
shouldRemoveSynthetics = false
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -257,6 +257,7 @@ abstract class PersistentLogicSystem(context: ConeInferenceContext) : LogicSyste
|
||||
}
|
||||
|
||||
override fun removeAllAboutVariable(flow: PersistentFlow, variable: RealVariable) {
|
||||
flow.logicStatements -= variable
|
||||
flow.approvedTypeStatements -= variable
|
||||
flow.approvedTypeStatementsDiff -= variable
|
||||
// TODO: should we search variable in all logic statements?
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
digraph functionCallBound_kt {
|
||||
graph [splines=ortho nodesep=3]
|
||||
node [shape=box penwidth=2]
|
||||
edge [penwidth=2]
|
||||
|
||||
subgraph cluster_0 {
|
||||
color=red
|
||||
0 [label="Enter function <init>" style="filled" fillcolor=red];
|
||||
1 [label="Exit function <init>" style="filled" fillcolor=red];
|
||||
}
|
||||
|
||||
0 -> {1};
|
||||
|
||||
subgraph cluster_1 {
|
||||
color=red
|
||||
2 [label="Enter function <init>" style="filled" fillcolor=red];
|
||||
3 [label="Exit function <init>" style="filled" fillcolor=red];
|
||||
}
|
||||
|
||||
2 -> {3};
|
||||
|
||||
subgraph cluster_2 {
|
||||
color=red
|
||||
4 [label="Enter function getter" style="filled" fillcolor=red];
|
||||
5 [label="Exit function getter" style="filled" fillcolor=red];
|
||||
}
|
||||
|
||||
4 -> {5};
|
||||
|
||||
subgraph cluster_3 {
|
||||
color=red
|
||||
6 [label="Enter property" style="filled" fillcolor=red];
|
||||
7 [label="Access variable R|<local>/data|"];
|
||||
8 [label="Exit property" style="filled" fillcolor=red];
|
||||
}
|
||||
|
||||
6 -> {7};
|
||||
7 -> {8};
|
||||
|
||||
subgraph cluster_4 {
|
||||
color=red
|
||||
9 [label="Enter function isOk" style="filled" fillcolor=red];
|
||||
10 [label="Const: Boolean(true)"];
|
||||
11 [label="Jump: ^isOk Boolean(true)"];
|
||||
12 [label="Stub" style="filled" fillcolor=gray];
|
||||
13 [label="Exit function isOk" style="filled" fillcolor=red];
|
||||
}
|
||||
|
||||
9 -> {10};
|
||||
10 -> {11};
|
||||
11 -> {13};
|
||||
11 -> {12} [style=dotted];
|
||||
12 -> {13} [style=dotted];
|
||||
|
||||
subgraph cluster_5 {
|
||||
color=red
|
||||
14 [label="Enter function check" style="filled" fillcolor=red];
|
||||
subgraph cluster_6 {
|
||||
color=blue
|
||||
15 [label="Enter when"];
|
||||
subgraph cluster_7 {
|
||||
color=blue
|
||||
16 [label="Enter when branch condition "];
|
||||
17 [label="Access variable R|<local>/base|"];
|
||||
18 [label="Type operator: (R|<local>/base| as? R|Sub|)"];
|
||||
19 [label="Enter safe call"];
|
||||
20 [label="Function call: (R|<local>/base| as? R|Sub|)?.R|/isOk|()"];
|
||||
21 [label="Exit safe call"];
|
||||
22 [label="Const: Boolean(true)"];
|
||||
23 [label="Operator =="];
|
||||
24 [label="Exit when branch condition"];
|
||||
}
|
||||
subgraph cluster_8 {
|
||||
color=blue
|
||||
25 [label="Enter when branch condition else"];
|
||||
26 [label="Exit when branch condition"];
|
||||
}
|
||||
27 [label="Enter when branch result"];
|
||||
subgraph cluster_9 {
|
||||
color=blue
|
||||
28 [label="Enter block"];
|
||||
29 [label="Access variable R|<local>/base|"];
|
||||
30 [label="Exit block"];
|
||||
}
|
||||
31 [label="Exit when branch result"];
|
||||
32 [label="Enter when branch result"];
|
||||
subgraph cluster_10 {
|
||||
color=blue
|
||||
33 [label="Enter block"];
|
||||
34 [label="Access variable R|<local>/base|"];
|
||||
35 [label="Access variable R|/Sub.data|"];
|
||||
36 [label="Exit block"];
|
||||
}
|
||||
37 [label="Exit when branch result"];
|
||||
38 [label="Exit when"];
|
||||
}
|
||||
39 [label="Jump: ^check when () {
|
||||
==((R|<local>/base| as? R|Sub|)?.R|/isOk|(), Boolean(true)) -> {
|
||||
R|<local>/base|.R|/Sub.data|
|
||||
}
|
||||
else -> {
|
||||
R|<local>/base|
|
||||
}
|
||||
}
|
||||
"];
|
||||
40 [label="Stub" style="filled" fillcolor=gray];
|
||||
41 [label="Exit function check" style="filled" fillcolor=red];
|
||||
}
|
||||
|
||||
14 -> {15};
|
||||
15 -> {16};
|
||||
16 -> {17};
|
||||
17 -> {18};
|
||||
18 -> {19 21};
|
||||
19 -> {20};
|
||||
20 -> {21};
|
||||
21 -> {22};
|
||||
22 -> {23};
|
||||
23 -> {24};
|
||||
24 -> {32 25};
|
||||
25 -> {26};
|
||||
26 -> {27};
|
||||
27 -> {28};
|
||||
28 -> {29};
|
||||
29 -> {30};
|
||||
30 -> {31};
|
||||
31 -> {38};
|
||||
32 -> {33};
|
||||
33 -> {34};
|
||||
34 -> {35};
|
||||
35 -> {36};
|
||||
36 -> {37};
|
||||
37 -> {38};
|
||||
38 -> {39};
|
||||
39 -> {41};
|
||||
39 -> {40} [style=dotted];
|
||||
40 -> {41} [style=dotted];
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// !DUMP_CFG
|
||||
|
||||
open class Base
|
||||
class Sub(val data: Base): Base()
|
||||
|
||||
fun Sub.isOk() = true
|
||||
|
||||
fun check(base: Base): Base =
|
||||
when {
|
||||
(base as? Sub)?.isOk() == true -> {
|
||||
base.data
|
||||
}
|
||||
else -> {
|
||||
base
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
FILE: functionCallBound.kt
|
||||
public open class Base : R|kotlin/Any| {
|
||||
public constructor(): R|Base| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final class Sub : R|Base| {
|
||||
public constructor(data: R|Base|): R|Sub| {
|
||||
super<R|Base|>()
|
||||
}
|
||||
|
||||
public final val data: R|Base| = R|<local>/data|
|
||||
public get(): R|Base|
|
||||
|
||||
}
|
||||
public final fun R|Sub|.isOk(): R|kotlin/Boolean| {
|
||||
^isOk Boolean(true)
|
||||
}
|
||||
public final fun check(base: R|Base|): R|Base| {
|
||||
^check when () {
|
||||
==((R|<local>/base| as? R|Sub|)?.R|/isOk|(), Boolean(true)) -> {
|
||||
R|<local>/base|.R|/Sub.data|
|
||||
}
|
||||
else -> {
|
||||
R|<local>/base|
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -1535,6 +1535,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
public void testBoundSmartcastsInBranches() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionCallBound.kt")
|
||||
public void testFunctionCallBound() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/resolve/testData/resolve/smartcasts/controlStructures")
|
||||
|
||||
Generated
+5
@@ -1535,6 +1535,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
public void testBoundSmartcastsInBranches() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionCallBound.kt")
|
||||
public void testFunctionCallBound() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/resolve/testData/resolve/smartcasts/controlStructures")
|
||||
|
||||
@@ -19,8 +19,8 @@ fun g(a: SomeClass?) {
|
||||
val b = (a as? SomeSubClass)?.foo
|
||||
if (b != null) {
|
||||
// 'a' can be cast to SomeSubClass
|
||||
a.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
a.<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
a.hashCode()
|
||||
a.foo
|
||||
(a as? SomeSubClass).<!INAPPLICABLE_CANDIDATE!>foo<!>
|
||||
(a as SomeSubClass).foo
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ fun g(a: SomeClass?) {
|
||||
val b = (a as? SomeSubClass)?.foo
|
||||
if (b != null) {
|
||||
// 'a' can be cast to SomeSubClass
|
||||
a.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
a.<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
a.hashCode()
|
||||
a.foo
|
||||
(a as? SomeSubClass).<!INAPPLICABLE_CANDIDATE!>foo<!>
|
||||
(a as SomeSubClass).foo
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ fun g(a: SomeClass?) {
|
||||
c = Impl
|
||||
if (c != null) {
|
||||
// 'a' cannot be cast to SomeSubClass
|
||||
a.hashCode()
|
||||
a.foo
|
||||
a.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
a.<!UNRESOLVED_REFERENCE!>foo<!>
|
||||
(a as? SomeSubClass).<!INAPPLICABLE_CANDIDATE!>foo<!>
|
||||
c.hashCode()
|
||||
c.foo
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ fun kt4565_2(a: SomeClass?) {
|
||||
}
|
||||
val extra = (a as? SubClass)?.extra
|
||||
if (extra != null) {
|
||||
a.<!UNRESOLVED_REFERENCE!>extra<!>.<!UNRESOLVED_REFERENCE!>hashCode<!>()
|
||||
a.extra.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user