From 43a2ad0467d1008780eee2b75a531934980697c1 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 16 Apr 2021 15:47:44 +0300 Subject: [PATCH] FIR: don't flatten for loop blocks in raw FIR builder --- .../testData/resolve/cfg/complex.dot | 115 +-- .../testData/resolve/cfg/complex.fir.txt | 15 +- .../testData/resolve/cfg/loops.dot | 545 +++++------ .../testData/resolve/cfg/loops.fir.txt | 11 +- .../resolve/expresssions/enumValues.fir.txt | 11 +- .../extendedCheckers/CanBeValChecker.fir.txt | 11 +- .../emptyRangeChecker/NoWarning.fir.txt | 27 +- .../emptyRangeChecker/Warning.fir.txt | 27 +- .../unused/manyLocalVariables.fir.txt | 25 +- .../testData/resolve/fib.fir.txt | 15 +- .../nestedExtensionFunctionType.fir.txt | 22 +- .../boundSmartcastsInBranches.dot | 877 +++++++++--------- .../boundSmartcastsInBranches.fir.txt | 19 +- .../resolve/smartcasts/smartcastToNothing.dot | 169 ++-- .../smartcasts/smartcastToNothing.fir.txt | 17 +- .../varargInPrimaryConstructor.fir.txt | 22 +- .../resolveWithStdlib/components.fir.txt | 13 +- .../fromSource/good/callsInPlace/flow.dot | 115 +-- .../fromSource/good/callsInPlace/flow.fir.txt | 11 +- .../diagnostics/forLoopChecker.fir.txt | 99 +- .../problems/DeepCopyIrTree.fir.txt | 19 +- .../problems/valueOfOrNull.fir.txt | 15 +- .../checkers/expression/FirForLoopChecker.kt | 71 +- .../converter/DeclarationsConverter.kt | 3 +- .../kotlin/fir/builder/RawFirBuilder.kt | 6 +- .../testData/rawBuilder/expressions/for.txt | 76 +- .../illegalConstructionInContractBlock.fir.kt | 4 +- 27 files changed, 1255 insertions(+), 1105 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot index fe0c1fe4a1e..6f28332ac57 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.dot @@ -191,63 +191,68 @@ digraph complex_kt { subgraph cluster_19 { color=blue 56 [label="Enter block"]; - 57 [label="Access variable this@R|/firstIsInstanceOrNull|"]; - 58 [label="Function call: this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride|>|()"]; - 59 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; subgraph cluster_20 { color=blue - 60 [label="Enter while loop"]; + 57 [label="Enter block"]; + 58 [label="Access variable this@R|/firstIsInstanceOrNull|"]; + 59 [label="Function call: this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride|>|()"]; + 60 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; subgraph cluster_21 { color=blue - 61 [label="Enter loop condition"]; - 62 [label="Access variable R|/|"]; - 63 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; - 64 [label="Exit loop condition"]; - } - subgraph cluster_22 { - color=blue - 65 [label="Enter loop block"]; + 61 [label="Enter while loop"]; + subgraph cluster_22 { + color=blue + 62 [label="Enter loop condition"]; + 63 [label="Access variable R|/|"]; + 64 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; + 65 [label="Exit loop condition"]; + } subgraph cluster_23 { color=blue - 66 [label="Enter block"]; - 67 [label="Access variable R|/|"]; - 68 [label="Function call: R|/|.R|SubstitutionOverride|()"]; - 69 [label="Variable declaration: lval element: R|kotlin/Any?|"]; + 66 [label="Enter loop block"]; subgraph cluster_24 { color=blue - 70 [label="Enter when"]; + 67 [label="Enter block"]; + 68 [label="Access variable R|/|"]; + 69 [label="Function call: R|/|.R|SubstitutionOverride|()"]; + 70 [label="Variable declaration: lval element: R|kotlin/Any?|"]; subgraph cluster_25 { color=blue - 71 [label="Enter when branch condition "]; - 72 [label="Access variable R|/element|"]; - 73 [label="Type operator: (R|/element| is R|T|)"]; - 74 [label="Exit when branch condition"]; + 71 [label="Enter when"]; + subgraph cluster_26 { + color=blue + 72 [label="Enter when branch condition "]; + 73 [label="Access variable R|/element|"]; + 74 [label="Type operator: (R|/element| is R|T|)"]; + 75 [label="Exit when branch condition"]; + } + 76 [label="Synthetic else branch"]; + 77 [label="Enter when branch result"]; + subgraph cluster_27 { + color=blue + 78 [label="Enter block"]; + 79 [label="Access variable R|/element|"]; + 80 [label="Jump: ^firstIsInstanceOrNull R|/element|"]; + 81 [label="Stub" style="filled" fillcolor=gray]; + 82 [label="Exit block" style="filled" fillcolor=gray]; + } + 83 [label="Exit when branch result" style="filled" fillcolor=gray]; + 84 [label="Exit when"]; } - 75 [label="Synthetic else branch"]; - 76 [label="Enter when branch result"]; - subgraph cluster_26 { - color=blue - 77 [label="Enter block"]; - 78 [label="Access variable R|/element|"]; - 79 [label="Jump: ^firstIsInstanceOrNull R|/element|"]; - 80 [label="Stub" style="filled" fillcolor=gray]; - 81 [label="Exit block" style="filled" fillcolor=gray]; - } - 82 [label="Exit when branch result" style="filled" fillcolor=gray]; - 83 [label="Exit when"]; + 85 [label="Exit block"]; } - 84 [label="Exit block"]; + 86 [label="Exit loop block"]; } - 85 [label="Exit loop block"]; + 87 [label="Exit whileloop"]; } - 86 [label="Exit whileloop"]; + 88 [label="Exit block"]; } - 87 [label="Const: Null(null)"]; - 88 [label="Jump: ^firstIsInstanceOrNull Null(null)"]; - 89 [label="Stub" style="filled" fillcolor=gray]; - 90 [label="Exit block" style="filled" fillcolor=gray]; + 89 [label="Const: Null(null)"]; + 90 [label="Jump: ^firstIsInstanceOrNull Null(null)"]; + 91 [label="Stub" style="filled" fillcolor=gray]; + 92 [label="Exit block" style="filled" fillcolor=gray]; } - 91 [label="Exit function firstIsInstanceOrNull" style="filled" fillcolor=red]; + 93 [label="Exit function firstIsInstanceOrNull" style="filled" fillcolor=red]; } 55 -> {56}; 56 -> {57}; @@ -258,8 +263,8 @@ digraph complex_kt { 61 -> {62}; 62 -> {63}; 63 -> {64}; - 64 -> {86 65}; - 65 -> {66}; + 64 -> {65}; + 65 -> {87 66}; 66 -> {67}; 67 -> {68}; 68 -> {69}; @@ -268,24 +273,26 @@ digraph complex_kt { 71 -> {72}; 72 -> {73}; 73 -> {74}; - 74 -> {76 75}; - 75 -> {83}; - 76 -> {77}; + 74 -> {75}; + 75 -> {77 76}; + 76 -> {84}; 77 -> {78}; 78 -> {79}; - 79 -> {91}; - 79 -> {80} [style=dotted]; + 79 -> {80}; + 80 -> {93}; 80 -> {81} [style=dotted]; 81 -> {82} [style=dotted]; 82 -> {83} [style=dotted]; - 83 -> {84}; + 83 -> {84} [style=dotted]; 84 -> {85}; - 85 -> {61} [color=green style=dashed]; - 86 -> {87}; + 85 -> {86}; + 86 -> {62} [color=green style=dashed]; 87 -> {88}; - 88 -> {91}; - 88 -> {89} [style=dotted]; - 89 -> {90} [style=dotted]; + 88 -> {89}; + 89 -> {90}; + 90 -> {93}; 90 -> {91} [style=dotted]; + 91 -> {92} [style=dotted]; + 92 -> {93} [style=dotted]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt index 306f1dcf7cc..df39f7729ba 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/complex.fir.txt @@ -25,13 +25,16 @@ FILE: complex.kt } public final inline fun R|kotlin/collections/List<*>|.firstIsInstanceOrNull(): R|T?| { - lval : R|kotlin/collections/Iterator| = this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval element: R|kotlin/Any?| = R|/|.R|SubstitutionOverride|() - when () { - (R|/element| is R|T|) -> { - ^firstIsInstanceOrNull R|/element| + { + lval : R|kotlin/collections/Iterator| = this@R|/firstIsInstanceOrNull|.R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval element: R|kotlin/Any?| = R|/|.R|SubstitutionOverride|() + when () { + (R|/element| is R|T|) -> { + ^firstIsInstanceOrNull R|/element| + } } + } } diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot index 64898d2e32b..86207d2676c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot @@ -118,44 +118,49 @@ digraph loops_kt { subgraph cluster_13 { color=blue 37 [label="Enter block"]; - 38 [label="Const: Int(0)"]; - 39 [label="Const: Int(5)"]; - 40 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...)"]; - 41 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...).R|kotlin/ranges/IntProgression.iterator|()"]; - 42 [label="Variable declaration: lval : R|kotlin/collections/IntIterator|"]; subgraph cluster_14 { color=blue - 43 [label="Enter while loop"]; + 38 [label="Enter block"]; + 39 [label="Const: Int(0)"]; + 40 [label="Const: Int(5)"]; + 41 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...)"]; + 42 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...).R|kotlin/ranges/IntProgression.iterator|()"]; + 43 [label="Variable declaration: lval : R|kotlin/collections/IntIterator|"]; subgraph cluster_15 { color=blue - 44 [label="Enter loop condition"]; - 45 [label="Access variable R|/|"]; - 46 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; - 47 [label="Exit loop condition"]; - } - subgraph cluster_16 { - color=blue - 48 [label="Enter loop block"]; + 44 [label="Enter while loop"]; + subgraph cluster_16 { + color=blue + 45 [label="Enter loop condition"]; + 46 [label="Access variable R|/|"]; + 47 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; + 48 [label="Exit loop condition"]; + } subgraph cluster_17 { color=blue - 49 [label="Enter block"]; - 50 [label="Access variable R|/|"]; - 51 [label="Function call: R|/|.R|kotlin/collections/IntIterator.next|()"]; - 52 [label="Variable declaration: lval i: R|kotlin/Int|"]; - 53 [label="Access variable R|/x|"]; - 54 [label="Type operator: (R|/x| is R|kotlin/String|)"]; - 55 [label="Variable declaration: lval y: R|kotlin/Boolean|"]; - 56 [label="Exit block"]; + 49 [label="Enter loop block"]; + subgraph cluster_18 { + color=blue + 50 [label="Enter block"]; + 51 [label="Access variable R|/|"]; + 52 [label="Function call: R|/|.R|kotlin/collections/IntIterator.next|()"]; + 53 [label="Variable declaration: lval i: R|kotlin/Int|"]; + 54 [label="Access variable R|/x|"]; + 55 [label="Type operator: (R|/x| is R|kotlin/String|)"]; + 56 [label="Variable declaration: lval y: R|kotlin/Boolean|"]; + 57 [label="Exit block"]; + } + 58 [label="Exit loop block"]; } - 57 [label="Exit loop block"]; + 59 [label="Exit whileloop"]; } - 58 [label="Exit whileloop"]; + 60 [label="Exit block"]; } - 59 [label="Access variable R|/x|"]; - 60 [label="Type operator: (R|/x| is R|kotlin/String|)"]; - 61 [label="Exit block"]; + 61 [label="Access variable R|/x|"]; + 62 [label="Type operator: (R|/x| is R|kotlin/String|)"]; + 63 [label="Exit block"]; } - 62 [label="Exit function testFor" style="filled" fillcolor=red]; + 64 [label="Exit function testFor" style="filled" fillcolor=red]; } 36 -> {37}; 37 -> {38}; @@ -168,8 +173,8 @@ digraph loops_kt { 44 -> {45}; 45 -> {46}; 46 -> {47}; - 47 -> {58 48}; - 48 -> {49}; + 47 -> {48}; + 48 -> {59 49}; 49 -> {50}; 50 -> {51}; 51 -> {52}; @@ -178,226 +183,226 @@ digraph loops_kt { 54 -> {55}; 55 -> {56}; 56 -> {57}; - 57 -> {44} [color=green style=dashed]; - 58 -> {59}; + 57 -> {58}; + 58 -> {45} [color=green style=dashed]; 59 -> {60}; 60 -> {61}; 61 -> {62}; + 62 -> {63}; + 63 -> {64}; - subgraph cluster_18 { + subgraph cluster_19 { color=red - 63 [label="Enter function testWhileTrue" style="filled" fillcolor=red]; - subgraph cluster_19 { + 65 [label="Enter function testWhileTrue" style="filled" fillcolor=red]; + subgraph cluster_20 { color=blue - 64 [label="Enter block"]; - subgraph cluster_20 { + 66 [label="Enter block"]; + subgraph cluster_21 { color=blue - 65 [label="Enter while loop"]; - subgraph cluster_21 { - color=blue - 66 [label="Enter loop condition"]; - 67 [label="Const: Boolean(true)"]; - 68 [label="Exit loop condition"]; - } + 67 [label="Enter while loop"]; subgraph cluster_22 { color=blue - 69 [label="Enter loop block"]; - subgraph cluster_23 { - color=blue - 70 [label="Enter block"]; - 71 [label="Const: Int(1)"]; - 72 [label="Exit block"]; - } - 73 [label="Exit loop block"]; + 68 [label="Enter loop condition"]; + 69 [label="Const: Boolean(true)"]; + 70 [label="Exit loop condition"]; } - 74 [label="Exit whileloop" style="filled" fillcolor=gray]; + subgraph cluster_23 { + color=blue + 71 [label="Enter loop block"]; + subgraph cluster_24 { + color=blue + 72 [label="Enter block"]; + 73 [label="Const: Int(1)"]; + 74 [label="Exit block"]; + } + 75 [label="Exit loop block"]; + } + 76 [label="Exit whileloop" style="filled" fillcolor=gray]; } - 75 [label="Const: Int(1)" style="filled" fillcolor=gray]; - 76 [label="Exit block" style="filled" fillcolor=gray]; + 77 [label="Const: Int(1)" style="filled" fillcolor=gray]; + 78 [label="Exit block" style="filled" fillcolor=gray]; } - 77 [label="Exit function testWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 79 [label="Exit function testWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray]; } - 63 -> {64}; - 64 -> {65}; 65 -> {66}; 66 -> {67}; 67 -> {68}; 68 -> {69}; - 68 -> {74} [style=dotted]; 69 -> {70}; 70 -> {71}; + 70 -> {76} [style=dotted]; 71 -> {72}; 72 -> {73}; - 73 -> {66} [color=green style=dashed]; - 74 -> {75} [style=dotted]; - 75 -> {76} [style=dotted]; + 73 -> {74}; + 74 -> {75}; + 75 -> {68} [color=green style=dashed]; 76 -> {77} [style=dotted]; + 77 -> {78} [style=dotted]; + 78 -> {79} [style=dotted]; - subgraph cluster_24 { + subgraph cluster_25 { color=red - 78 [label="Enter function testWhileTrueWithBreak" style="filled" fillcolor=red]; - subgraph cluster_25 { + 80 [label="Enter function testWhileTrueWithBreak" style="filled" fillcolor=red]; + subgraph cluster_26 { color=blue - 79 [label="Enter block"]; - subgraph cluster_26 { + 81 [label="Enter block"]; + subgraph cluster_27 { color=blue - 80 [label="Enter while loop"]; - subgraph cluster_27 { - color=blue - 81 [label="Enter loop condition"]; - 82 [label="Const: Boolean(true)"]; - 83 [label="Exit loop condition"]; - } + 82 [label="Enter while loop"]; subgraph cluster_28 { color=blue - 84 [label="Enter loop block"]; - subgraph cluster_29 { + 83 [label="Enter loop condition"]; + 84 [label="Const: Boolean(true)"]; + 85 [label="Exit loop condition"]; + } + subgraph cluster_29 { + color=blue + 86 [label="Enter loop block"]; + subgraph cluster_30 { color=blue - 85 [label="Enter block"]; - subgraph cluster_30 { + 87 [label="Enter block"]; + subgraph cluster_31 { color=blue - 86 [label="Enter when"]; - subgraph cluster_31 { - color=blue - 87 [label="Enter when branch condition "]; - 88 [label="Access variable R|/b|"]; - 89 [label="Exit when branch condition"]; - } - 90 [label="Synthetic else branch"]; - 91 [label="Enter when branch result"]; + 88 [label="Enter when"]; subgraph cluster_32 { color=blue - 92 [label="Enter block"]; - 93 [label="Jump: break@@@[Boolean(true)] "]; - 94 [label="Stub" style="filled" fillcolor=gray]; - 95 [label="Exit block" style="filled" fillcolor=gray]; + 89 [label="Enter when branch condition "]; + 90 [label="Access variable R|/b|"]; + 91 [label="Exit when branch condition"]; } - 96 [label="Exit when branch result" style="filled" fillcolor=gray]; - 97 [label="Exit when"]; + 92 [label="Synthetic else branch"]; + 93 [label="Enter when branch result"]; + subgraph cluster_33 { + color=blue + 94 [label="Enter block"]; + 95 [label="Jump: break@@@[Boolean(true)] "]; + 96 [label="Stub" style="filled" fillcolor=gray]; + 97 [label="Exit block" style="filled" fillcolor=gray]; + } + 98 [label="Exit when branch result" style="filled" fillcolor=gray]; + 99 [label="Exit when"]; } - 98 [label="Exit block"]; + 100 [label="Exit block"]; } - 99 [label="Exit loop block"]; + 101 [label="Exit loop block"]; } - 100 [label="Exit whileloop"]; + 102 [label="Exit whileloop"]; } - 101 [label="Const: Int(1)"]; - 102 [label="Exit block"]; + 103 [label="Const: Int(1)"]; + 104 [label="Exit block"]; } - 103 [label="Exit function testWhileTrueWithBreak" style="filled" fillcolor=red]; + 105 [label="Exit function testWhileTrueWithBreak" style="filled" fillcolor=red]; } - 78 -> {79}; - 79 -> {80}; 80 -> {81}; 81 -> {82}; 82 -> {83}; 83 -> {84}; - 83 -> {100} [style=dotted]; 84 -> {85}; 85 -> {86}; + 85 -> {102} [style=dotted]; 86 -> {87}; 87 -> {88}; 88 -> {89}; - 89 -> {91 90}; - 90 -> {97}; - 91 -> {92}; - 92 -> {93}; - 93 -> {100}; - 93 -> {94} [style=dotted]; - 94 -> {95} [style=dotted]; + 89 -> {90}; + 90 -> {91}; + 91 -> {93 92}; + 92 -> {99}; + 93 -> {94}; + 94 -> {95}; + 95 -> {102}; 95 -> {96} [style=dotted]; 96 -> {97} [style=dotted]; - 97 -> {98}; - 98 -> {99}; - 99 -> {81} [color=green style=dashed]; + 97 -> {98} [style=dotted]; + 98 -> {99} [style=dotted]; + 99 -> {100}; 100 -> {101}; - 101 -> {102}; + 101 -> {83} [color=green style=dashed]; 102 -> {103}; + 103 -> {104}; + 104 -> {105}; - subgraph cluster_33 { + subgraph cluster_34 { color=red - 104 [label="Enter function testWhileFalse" style="filled" fillcolor=red]; - subgraph cluster_34 { + 106 [label="Enter function testWhileFalse" style="filled" fillcolor=red]; + subgraph cluster_35 { color=blue - 105 [label="Enter block"]; - subgraph cluster_35 { + 107 [label="Enter block"]; + subgraph cluster_36 { color=blue - 106 [label="Enter while loop"]; - subgraph cluster_36 { - color=blue - 107 [label="Enter loop condition"]; - 108 [label="Const: Boolean(false)"]; - 109 [label="Exit loop condition"]; - } + 108 [label="Enter while loop"]; subgraph cluster_37 { color=blue - 110 [label="Enter loop block" style="filled" fillcolor=gray]; - subgraph cluster_38 { - color=blue - 111 [label="Enter block" style="filled" fillcolor=gray]; - 112 [label="Const: Int(1)" style="filled" fillcolor=gray]; - 113 [label="Exit block" style="filled" fillcolor=gray]; - } - 114 [label="Exit loop block" style="filled" fillcolor=gray]; + 109 [label="Enter loop condition"]; + 110 [label="Const: Boolean(false)"]; + 111 [label="Exit loop condition"]; } - 115 [label="Exit whileloop"]; + subgraph cluster_38 { + color=blue + 112 [label="Enter loop block" style="filled" fillcolor=gray]; + subgraph cluster_39 { + color=blue + 113 [label="Enter block" style="filled" fillcolor=gray]; + 114 [label="Const: Int(1)" style="filled" fillcolor=gray]; + 115 [label="Exit block" style="filled" fillcolor=gray]; + } + 116 [label="Exit loop block" style="filled" fillcolor=gray]; + } + 117 [label="Exit whileloop"]; } - 116 [label="Const: Int(1)"]; - 117 [label="Exit block"]; + 118 [label="Const: Int(1)"]; + 119 [label="Exit block"]; } - 118 [label="Exit function testWhileFalse" style="filled" fillcolor=red]; + 120 [label="Exit function testWhileFalse" style="filled" fillcolor=red]; } - 104 -> {105}; - 105 -> {106}; 106 -> {107}; 107 -> {108}; 108 -> {109}; - 109 -> {115}; - 109 -> {110} [style=dotted]; - 110 -> {111} [style=dotted]; + 109 -> {110}; + 110 -> {111}; + 111 -> {117}; 111 -> {112} [style=dotted]; 112 -> {113} [style=dotted]; 113 -> {114} [style=dotted]; - 114 -> {107} [color=green style=dotted]; - 115 -> {116}; - 116 -> {117}; + 114 -> {115} [style=dotted]; + 115 -> {116} [style=dotted]; + 116 -> {109} [color=green style=dotted]; 117 -> {118}; - - subgraph cluster_39 { - color=red - 119 [label="Enter function testDoWhileTrue" style="filled" fillcolor=red]; - subgraph cluster_40 { - color=blue - 120 [label="Enter block"]; - subgraph cluster_41 { - color=blue - 121 [label="Enter do-while loop"]; - subgraph cluster_42 { - color=blue - 122 [label="Enter loop block"]; - subgraph cluster_43 { - color=blue - 123 [label="Enter block"]; - 124 [label="Const: Int(1)"]; - 125 [label="Exit block"]; - } - 126 [label="Exit loop block"]; - } - subgraph cluster_44 { - color=blue - 127 [label="Enter loop condition"]; - 128 [label="Const: Boolean(true)"]; - 129 [label="Exit loop condition"]; - } - 130 [label="Exit do-whileloop" style="filled" fillcolor=gray]; - } - 131 [label="Const: Int(1)" style="filled" fillcolor=gray]; - 132 [label="Exit block" style="filled" fillcolor=gray]; - } - 133 [label="Exit function testDoWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray]; - } + 118 -> {119}; 119 -> {120}; - 120 -> {121}; + + subgraph cluster_40 { + color=red + 121 [label="Enter function testDoWhileTrue" style="filled" fillcolor=red]; + subgraph cluster_41 { + color=blue + 122 [label="Enter block"]; + subgraph cluster_42 { + color=blue + 123 [label="Enter do-while loop"]; + subgraph cluster_43 { + color=blue + 124 [label="Enter loop block"]; + subgraph cluster_44 { + color=blue + 125 [label="Enter block"]; + 126 [label="Const: Int(1)"]; + 127 [label="Exit block"]; + } + 128 [label="Exit loop block"]; + } + subgraph cluster_45 { + color=blue + 129 [label="Enter loop condition"]; + 130 [label="Const: Boolean(true)"]; + 131 [label="Exit loop condition"]; + } + 132 [label="Exit do-whileloop" style="filled" fillcolor=gray]; + } + 133 [label="Const: Int(1)" style="filled" fillcolor=gray]; + 134 [label="Exit block" style="filled" fillcolor=gray]; + } + 135 [label="Exit function testDoWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray]; + } 121 -> {122}; 122 -> {123}; 123 -> {124}; @@ -406,128 +411,128 @@ digraph loops_kt { 126 -> {127}; 127 -> {128}; 128 -> {129}; - 129 -> {130} [style=dotted]; - 129 -> {122} [color=green style=dashed]; - 130 -> {131} [style=dotted]; + 129 -> {130}; + 130 -> {131}; 131 -> {132} [style=dotted]; + 131 -> {124} [color=green style=dashed]; 132 -> {133} [style=dotted]; + 133 -> {134} [style=dotted]; + 134 -> {135} [style=dotted]; - subgraph cluster_45 { + subgraph cluster_46 { color=red - 134 [label="Enter function testDoWhileTrueWithBreak" style="filled" fillcolor=red]; - subgraph cluster_46 { + 136 [label="Enter function testDoWhileTrueWithBreak" style="filled" fillcolor=red]; + subgraph cluster_47 { color=blue - 135 [label="Enter block"]; - subgraph cluster_47 { + 137 [label="Enter block"]; + subgraph cluster_48 { color=blue - 136 [label="Enter do-while loop"]; - subgraph cluster_48 { + 138 [label="Enter do-while loop"]; + subgraph cluster_49 { color=blue - 137 [label="Enter loop block"]; - subgraph cluster_49 { + 139 [label="Enter loop block"]; + subgraph cluster_50 { color=blue - 138 [label="Enter block"]; - subgraph cluster_50 { + 140 [label="Enter block"]; + subgraph cluster_51 { color=blue - 139 [label="Enter when"]; - subgraph cluster_51 { - color=blue - 140 [label="Enter when branch condition "]; - 141 [label="Access variable R|/b|"]; - 142 [label="Exit when branch condition"]; - } - 143 [label="Synthetic else branch"]; - 144 [label="Enter when branch result"]; + 141 [label="Enter when"]; subgraph cluster_52 { color=blue - 145 [label="Enter block"]; - 146 [label="Jump: break@@@[Boolean(true)] "]; - 147 [label="Stub" style="filled" fillcolor=gray]; - 148 [label="Exit block" style="filled" fillcolor=gray]; + 142 [label="Enter when branch condition "]; + 143 [label="Access variable R|/b|"]; + 144 [label="Exit when branch condition"]; } - 149 [label="Exit when branch result" style="filled" fillcolor=gray]; - 150 [label="Exit when"]; + 145 [label="Synthetic else branch"]; + 146 [label="Enter when branch result"]; + subgraph cluster_53 { + color=blue + 147 [label="Enter block"]; + 148 [label="Jump: break@@@[Boolean(true)] "]; + 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"]; } - 151 [label="Exit block"]; + 153 [label="Exit block"]; } - 152 [label="Exit loop block"]; + 154 [label="Exit loop block"]; } - subgraph cluster_53 { + subgraph cluster_54 { color=blue - 153 [label="Enter loop condition"]; - 154 [label="Const: Boolean(true)"]; - 155 [label="Exit loop condition"]; + 155 [label="Enter loop condition"]; + 156 [label="Const: Boolean(true)"]; + 157 [label="Exit loop condition"]; } - 156 [label="Exit do-whileloop"]; + 158 [label="Exit do-whileloop"]; } - 157 [label="Const: Int(1)"]; - 158 [label="Exit block"]; + 159 [label="Const: Int(1)"]; + 160 [label="Exit block"]; } - 159 [label="Exit function testDoWhileTrueWithBreak" style="filled" fillcolor=red]; + 161 [label="Exit function testDoWhileTrueWithBreak" style="filled" fillcolor=red]; } - 134 -> {135}; - 135 -> {136}; 136 -> {137}; 137 -> {138}; 138 -> {139}; 139 -> {140}; 140 -> {141}; 141 -> {142}; - 142 -> {144 143}; - 143 -> {150}; - 144 -> {145}; - 145 -> {146}; - 146 -> {156}; - 146 -> {147} [style=dotted]; - 147 -> {148} [style=dotted]; + 142 -> {143}; + 143 -> {144}; + 144 -> {146 145}; + 145 -> {152}; + 146 -> {147}; + 147 -> {148}; + 148 -> {158}; 148 -> {149} [style=dotted]; 149 -> {150} [style=dotted]; - 150 -> {151}; - 151 -> {152}; + 150 -> {151} [style=dotted]; + 151 -> {152} [style=dotted]; 152 -> {153}; 153 -> {154}; 154 -> {155}; - 155 -> {156} [style=dotted]; - 155 -> {137} [color=green style=dashed]; + 155 -> {156}; 156 -> {157}; - 157 -> {158}; + 157 -> {158} [style=dotted]; + 157 -> {139} [color=green style=dashed]; 158 -> {159}; - - subgraph cluster_54 { - color=red - 160 [label="Enter function testDoWhileFalse" style="filled" fillcolor=red]; - subgraph cluster_55 { - color=blue - 161 [label="Enter block"]; - subgraph cluster_56 { - color=blue - 162 [label="Enter do-while loop"]; - subgraph cluster_57 { - color=blue - 163 [label="Enter loop block"]; - subgraph cluster_58 { - color=blue - 164 [label="Enter block"]; - 165 [label="Const: Int(1)"]; - 166 [label="Exit block"]; - } - 167 [label="Exit loop block"]; - } - subgraph cluster_59 { - color=blue - 168 [label="Enter loop condition"]; - 169 [label="Const: Boolean(false)"]; - 170 [label="Exit loop condition"]; - } - 171 [label="Exit do-whileloop"]; - } - 172 [label="Const: Int(1)"]; - 173 [label="Exit block"]; - } - 174 [label="Exit function testDoWhileFalse" style="filled" fillcolor=red]; - } + 159 -> {160}; 160 -> {161}; - 161 -> {162}; + + subgraph cluster_55 { + color=red + 162 [label="Enter function testDoWhileFalse" style="filled" fillcolor=red]; + subgraph cluster_56 { + color=blue + 163 [label="Enter block"]; + subgraph cluster_57 { + color=blue + 164 [label="Enter do-while loop"]; + subgraph cluster_58 { + color=blue + 165 [label="Enter loop block"]; + subgraph cluster_59 { + color=blue + 166 [label="Enter block"]; + 167 [label="Const: Int(1)"]; + 168 [label="Exit block"]; + } + 169 [label="Exit loop block"]; + } + subgraph cluster_60 { + color=blue + 170 [label="Enter loop condition"]; + 171 [label="Const: Boolean(false)"]; + 172 [label="Exit loop condition"]; + } + 173 [label="Exit do-whileloop"]; + } + 174 [label="Const: Int(1)"]; + 175 [label="Exit block"]; + } + 176 [label="Exit function testDoWhileFalse" style="filled" fillcolor=red]; + } 162 -> {163}; 163 -> {164}; 164 -> {165}; @@ -537,9 +542,11 @@ digraph loops_kt { 168 -> {169}; 169 -> {170}; 170 -> {171}; - 170 -> {163} [color=green style=dotted]; 171 -> {172}; 172 -> {173}; + 172 -> {165} [color=green style=dotted]; 173 -> {174}; + 174 -> {175}; + 175 -> {176}; } diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/loops.fir.txt b/compiler/fir/analysis-tests/testData/resolve/cfg/loops.fir.txt index a72a595e925..ef3dcf8c917 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/loops.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/loops.fir.txt @@ -14,10 +14,13 @@ FILE: loops.kt (R|/x| is R|kotlin/String|) } public final fun testFor(x: R|kotlin/Any?|): R|kotlin/Unit| { - lval : R|kotlin/collections/IntIterator| = Int(0).R|kotlin/Int.rangeTo|(Int(5)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() - lval y: R|kotlin/Boolean| = (R|/x| is R|kotlin/String|) + { + lval : R|kotlin/collections/IntIterator| = Int(0).R|kotlin/Int.rangeTo|(Int(5)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + lval y: R|kotlin/Boolean| = (R|/x| is R|kotlin/String|) + } + } (R|/x| is R|kotlin/String|) diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/enumValues.fir.txt b/compiler/fir/analysis-tests/testData/resolve/expresssions/enumValues.fir.txt index d96ef292b3d..21bcb76fb7d 100644 --- a/compiler/fir/analysis-tests/testData/resolve/expresssions/enumValues.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/enumValues.fir.txt @@ -20,10 +20,13 @@ FILE: enumValues.kt } public final fun foo(): R|kotlin/Unit| { lval values: R|kotlin/Array| = Q|MyEnum|.R|/MyEnum.values|() - lval : R|kotlin/collections/Iterator| = R|/values|.R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval value: R|MyEnum| = R|/|.R|SubstitutionOverride|() - R|/value|.R|/MyEnum.bar|() + { + lval : R|kotlin/collections/Iterator| = R|/values|.R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval value: R|MyEnum| = R|/|.R|SubstitutionOverride|() + R|/value|.R|/MyEnum.bar|() + } + } lval first: R|MyEnum| = Q|MyEnum|.R|/MyEnum.valueOf|(String(FIRST)) diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/CanBeValChecker.fir.txt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/CanBeValChecker.fir.txt index f0f6f92e02d..76a9af6435f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/CanBeValChecker.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/CanBeValChecker.fir.txt @@ -66,10 +66,13 @@ FILE: CanBeValChecker.kt public final fun stackOverflowBug(): R|kotlin/Unit| { lvar a: R|kotlin/Int| R|/a| = Int(1) - lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/Int.rangeTo|(Int(10)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() - R|kotlin/io/print|(R|/i|) + { + lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/Int.rangeTo|(Int(10)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + R|kotlin/io/print|(R|/i|) + } + } } diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/NoWarning.fir.txt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/NoWarning.fir.txt index 6bad4d04889..28083b90670 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/NoWarning.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/NoWarning.fir.txt @@ -1,8 +1,11 @@ FILE: NoWarning.kt public final fun foo(): R|kotlin/Unit| { - lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/Int.rangeTo|(Int(2)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + { + lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/Int.rangeTo|(Int(2)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + } + } lval a: R|kotlin/ranges/IntRange| = Int(3).R|kotlin/Int.rangeTo|(Int(4)) @@ -14,9 +17,12 @@ FILE: NoWarning.kt } public final fun backward(): R|kotlin/Unit| { - lval : R|kotlin/collections/IntIterator| = Int(2).R|kotlin/ranges/downTo|(Int(1)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + { + lval : R|kotlin/collections/IntIterator| = Int(2).R|kotlin/ranges/downTo|(Int(1)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + } + } lval a: R|kotlin/ranges/IntProgression| = Int(4).R|kotlin/ranges/downTo|(Int(3)) @@ -28,9 +34,12 @@ FILE: NoWarning.kt } public final fun until(): R|kotlin/Unit| { - lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/ranges/until|(Int(2)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + { + lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/ranges/until|(Int(2)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + } + } lval a: R|kotlin/ranges/IntRange| = Int(3).R|kotlin/ranges/until|(Int(4)) diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/Warning.fir.txt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/Warning.fir.txt index 99630ec9a6b..ae450a6b177 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/Warning.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/emptyRangeChecker/Warning.fir.txt @@ -1,8 +1,11 @@ FILE: Warning.kt public final fun foo(): R|kotlin/Unit| { - lval : R|kotlin/collections/IntIterator| = Int(2).R|kotlin/Int.rangeTo|(Int(1)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + { + lval : R|kotlin/collections/IntIterator| = Int(2).R|kotlin/Int.rangeTo|(Int(1)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + } + } lval a: R|kotlin/ranges/IntRange| = Int(10).R|kotlin/Int.rangeTo|(Int(0)) @@ -14,9 +17,12 @@ FILE: Warning.kt } public final fun backward(): R|kotlin/Unit| { - lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/ranges/downTo|(Int(2)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + { + lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/ranges/downTo|(Int(2)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + } + } lval a: R|kotlin/ranges/IntProgression| = Int(-3).R|kotlin/ranges/downTo|(Int(4)) @@ -28,9 +34,12 @@ FILE: Warning.kt } public final fun until(): R|kotlin/Unit| { - lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/ranges/until|(Int(1)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + { + lval : R|kotlin/collections/IntIterator| = Int(1).R|kotlin/ranges/until|(Int(1)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + } + } lval a: R|kotlin/ranges/IntRange| = Int(4).R|kotlin/ranges/until|(Int(3)) diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/manyLocalVariables.fir.txt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/manyLocalVariables.fir.txt index 0dcd5fdd47b..4fd06d51c3d 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/manyLocalVariables.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/unused/manyLocalVariables.fir.txt @@ -3,18 +3,21 @@ FILE: manyLocalVariables.kt lvar a: R|kotlin/Int| = Int(1) lvar b: R|kotlin/Int| = Int(2) lvar c: R|kotlin/Int| = Int(3) - lval : R|kotlin/collections/IntIterator| = Int(0).R|kotlin/Int.rangeTo|(Int(5)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() - when () { - ==(R|/a|, Int(2)) -> { - R|/b| = R|/c| - R|/c| = R|/a| - } - else -> { - R|/b| = R|/a| - R|/c| = R|/b| + { + lval : R|kotlin/collections/IntIterator| = Int(0).R|kotlin/Int.rangeTo|(Int(5)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + when () { + ==(R|/a|, Int(2)) -> { + R|/b| = R|/c| + R|/c| = R|/a| + } + else -> { + R|/b| = R|/a| + R|/c| = R|/b| + } } + } } diff --git a/compiler/fir/analysis-tests/testData/resolve/fib.fir.txt b/compiler/fir/analysis-tests/testData/resolve/fib.fir.txt index c385a74db75..157e3b4715a 100644 --- a/compiler/fir/analysis-tests/testData/resolve/fib.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/fib.fir.txt @@ -8,12 +8,15 @@ FILE: fib.kt lvar current: R|kotlin/Int| = Int(1) lvar prev: R|kotlin/Int| = Int(1) - lval : R|kotlin/collections/IntIterator| = Int(2).R|kotlin/Int.rangeTo|(R|/n|).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() - lval temp: R|kotlin/Int| = R|/current| - R|/current| = R|/current|.R|kotlin/Int.plus|(R|/prev|) - R|/prev| = R|/temp| + { + lval : R|kotlin/collections/IntIterator| = Int(2).R|kotlin/Int.rangeTo|(R|/n|).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + lval temp: R|kotlin/Int| = R|/current| + R|/current| = R|/current|.R|kotlin/Int.plus|(R|/prev|) + R|/prev| = R|/temp| + } + } ^fibIterative R|/current| diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.fir.txt index 19ed267189d..0cbe9aaa162 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/nestedExtensionFunctionType.fir.txt @@ -5,18 +5,24 @@ FILE: nestedExtensionFunctionType.kt R|/f|.R|SubstitutionOverride|(R|/a|) } public final fun test_1(a: R|A|, ys: R|kotlin/collections/List<@ExtensionFunctionType kotlin/Function1>|): R|kotlin/Unit| { - lval : R|kotlin/collections/Iterator<@ExtensionFunctionType kotlin/Function1>| = R|/ys|.R|SubstitutionOverride>|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval y: R|(A) -> kotlin/Unit| = R|/|.R|SubstitutionOverride kotlin/Unit|>|() - R|/y|.R|SubstitutionOverride|(R|/a|) + { + lval : R|kotlin/collections/Iterator<@ExtensionFunctionType kotlin/Function1>| = R|/ys|.R|SubstitutionOverride>|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval y: R|(A) -> kotlin/Unit| = R|/|.R|SubstitutionOverride kotlin/Unit|>|() + R|/y|.R|SubstitutionOverride|(R|/a|) + } + } } public final fun test_2(a: R|A|, vararg zs: @R|kotlin/ExtensionFunctionType|() R|kotlin/Array>|): R|kotlin/Unit| { - lval : R|kotlin/collections/Iterator<@ExtensionFunctionType kotlin/Function1>| = R|/zs|.R|SubstitutionOverride)>|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval z: R|(A) -> kotlin/Unit| = R|/|.R|SubstitutionOverride kotlin/Unit|>|() - R|/z|.R|SubstitutionOverride|(R|/a|) + { + lval : R|kotlin/collections/Iterator<@ExtensionFunctionType kotlin/Function1>| = R|/zs|.R|SubstitutionOverride)>|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval z: R|(A) -> kotlin/Unit| = R|/|.R|SubstitutionOverride kotlin/Unit|>|() + R|/z|.R|SubstitutionOverride|(R|/a|) + } + } } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot index 15d374c3afd..38e0f7bdb2e 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot @@ -41,64 +41,69 @@ digraph boundSmartcastsInBranches_kt { 10 [label="Enter block"]; 11 [label="Const: Null(null)"]; 12 [label="Variable declaration: lvar goodA: R|A?|"]; - 13 [label="Access variable R|/list|"]; - 14 [label="Function call: R|/list|.R|SubstitutionOverride|>|()"]; - 15 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; subgraph cluster_5 { color=blue - 16 [label="Enter while loop"]; + 13 [label="Enter block"]; + 14 [label="Access variable R|/list|"]; + 15 [label="Function call: R|/list|.R|SubstitutionOverride|>|()"]; + 16 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; subgraph cluster_6 { color=blue - 17 [label="Enter loop condition"]; - 18 [label="Access variable R|/|"]; - 19 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; - 20 [label="Exit loop condition"]; - } - subgraph cluster_7 { - color=blue - 21 [label="Enter loop block"]; + 17 [label="Enter while loop"]; + subgraph cluster_7 { + color=blue + 18 [label="Enter loop condition"]; + 19 [label="Access variable R|/|"]; + 20 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; + 21 [label="Exit loop condition"]; + } subgraph cluster_8 { color=blue - 22 [label="Enter block"]; - 23 [label="Access variable R|/|"]; - 24 [label="Function call: R|/|.R|SubstitutionOverride|()"]; - 25 [label="Variable declaration: lval a: R|A|"]; + 22 [label="Enter loop block"]; subgraph cluster_9 { color=blue - 26 [label="Enter when"]; + 23 [label="Enter block"]; + 24 [label="Access variable R|/|"]; + 25 [label="Function call: R|/|.R|SubstitutionOverride|()"]; + 26 [label="Variable declaration: lval a: R|A|"]; subgraph cluster_10 { color=blue - 27 [label="Enter when branch condition "]; - 28 [label="Access variable R|/goodA|"]; - 29 [label="Const: Null(null)"]; - 30 [label="Equality operator =="]; - 31 [label="Exit when branch condition"]; + 27 [label="Enter when"]; + subgraph cluster_11 { + color=blue + 28 [label="Enter when branch condition "]; + 29 [label="Access variable R|/goodA|"]; + 30 [label="Const: Null(null)"]; + 31 [label="Equality operator =="]; + 32 [label="Exit when branch condition"]; + } + 33 [label="Synthetic else branch"]; + 34 [label="Enter when branch result"]; + subgraph cluster_12 { + color=blue + 35 [label="Enter block"]; + 36 [label="Access variable R|/a|"]; + 37 [label="Assignment: R|/goodA|"]; + 38 [label="Jump: continue@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] "]; + 39 [label="Stub" style="filled" fillcolor=gray]; + 40 [label="Exit block" style="filled" fillcolor=gray]; + } + 41 [label="Exit when branch result" style="filled" fillcolor=gray]; + 42 [label="Exit when"]; } - 32 [label="Synthetic else branch"]; - 33 [label="Enter when branch result"]; - subgraph cluster_11 { - color=blue - 34 [label="Enter block"]; - 35 [label="Access variable R|/a|"]; - 36 [label="Assignment: R|/goodA|"]; - 37 [label="Jump: continue@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] "]; - 38 [label="Stub" style="filled" fillcolor=gray]; - 39 [label="Exit block" style="filled" fillcolor=gray]; - } - 40 [label="Exit when branch result" style="filled" fillcolor=gray]; - 41 [label="Exit when"]; + 43 [label="Access variable R|/goodA|"]; + 44 [label="Access variable R|/A.s|"]; + 45 [label="Exit block"]; } - 42 [label="Access variable R|/goodA|"]; - 43 [label="Access variable R|/A.s|"]; - 44 [label="Exit block"]; + 46 [label="Exit loop block"]; } - 45 [label="Exit loop block"]; + 47 [label="Exit whileloop"]; } - 46 [label="Exit whileloop"]; + 48 [label="Exit block"]; } - 47 [label="Exit block"]; + 49 [label="Exit block"]; } - 48 [label="Exit function test_0" style="filled" fillcolor=red]; + 50 [label="Exit function test_0" style="filled" fillcolor=red]; } 9 -> {10}; 10 -> {11}; @@ -111,8 +116,8 @@ digraph boundSmartcastsInBranches_kt { 17 -> {18}; 18 -> {19}; 19 -> {20}; - 20 -> {46 21}; - 21 -> {22}; + 20 -> {21}; + 21 -> {47 22}; 22 -> {23}; 23 -> {24}; 24 -> {25}; @@ -122,89 +127,89 @@ digraph boundSmartcastsInBranches_kt { 28 -> {29}; 29 -> {30}; 30 -> {31}; - 31 -> {33 32}; - 32 -> {41}; - 33 -> {34}; + 31 -> {32}; + 32 -> {34 33}; + 33 -> {42}; 34 -> {35}; 35 -> {36}; 36 -> {37}; - 37 -> {38} [style=dotted]; - 37 -> {16} [color=green style=dashed]; + 37 -> {38}; 38 -> {39} [style=dotted]; + 38 -> {17} [color=green style=dashed]; 39 -> {40} [style=dotted]; 40 -> {41} [style=dotted]; - 41 -> {42}; + 41 -> {42} [style=dotted]; 42 -> {43}; 43 -> {44}; 44 -> {45}; - 45 -> {17} [color=green style=dashed]; - 46 -> {47}; + 45 -> {46}; + 46 -> {18} [color=green style=dashed]; 47 -> {48}; + 48 -> {49}; + 49 -> {50}; - subgraph cluster_12 { + subgraph cluster_13 { color=red - 49 [label="Enter function test_1" style="filled" fillcolor=red]; - subgraph cluster_13 { + 51 [label="Enter function test_1" style="filled" fillcolor=red]; + subgraph cluster_14 { color=blue - 50 [label="Enter block"]; - 51 [label="Variable declaration: lval x: R|kotlin/Any|"]; - subgraph cluster_14 { + 52 [label="Enter block"]; + 53 [label="Variable declaration: lval x: R|kotlin/Any|"]; + subgraph cluster_15 { color=blue - 52 [label="Enter when"]; - subgraph cluster_15 { - color=blue - 53 [label="Enter when branch condition "]; - 54 [label="Access variable R|/b|"]; - 55 [label="Exit when branch condition"]; - } + 54 [label="Enter when"]; subgraph cluster_16 { color=blue - 56 [label="Enter when branch condition else"]; + 55 [label="Enter when branch condition "]; + 56 [label="Access variable R|/b|"]; 57 [label="Exit when branch condition"]; } - 58 [label="Enter when branch result"]; subgraph cluster_17 { color=blue - 59 [label="Enter block"]; - 60 [label="Access variable R|/a|"]; - 61 [label="Assignment: R|/x|"]; - 62 [label="Exit block"]; + 58 [label="Enter when branch condition else"]; + 59 [label="Exit when branch condition"]; } - 63 [label="Exit when branch result"]; - 64 [label="Enter when branch result"]; + 60 [label="Enter when branch result"]; subgraph cluster_18 { color=blue - 65 [label="Enter block"]; - 66 [label="Function call: R|/A.A|()"]; - 67 [label="Assignment: R|/x|"]; - 68 [label="Exit block"]; + 61 [label="Enter block"]; + 62 [label="Access variable R|/a|"]; + 63 [label="Assignment: R|/x|"]; + 64 [label="Exit block"]; } - 69 [label="Exit when branch result"]; - 70 [label="Exit when"]; + 65 [label="Exit when branch result"]; + 66 [label="Enter when branch result"]; + subgraph cluster_19 { + color=blue + 67 [label="Enter block"]; + 68 [label="Function call: R|/A.A|()"]; + 69 [label="Assignment: R|/x|"]; + 70 [label="Exit block"]; + } + 71 [label="Exit when branch result"]; + 72 [label="Exit when"]; } - 71 [label="Access variable R|/x|"]; - 72 [label="Access variable R|/A.s|"]; - 73 [label="Exit block"]; + 73 [label="Access variable R|/x|"]; + 74 [label="Access variable R|/A.s|"]; + 75 [label="Exit block"]; } - 74 [label="Exit function test_1" style="filled" fillcolor=red]; + 76 [label="Exit function test_1" style="filled" fillcolor=red]; } - 49 -> {50}; - 50 -> {51}; 51 -> {52}; 52 -> {53}; 53 -> {54}; 54 -> {55}; - 55 -> {64 56}; + 55 -> {56}; 56 -> {57}; - 57 -> {58}; + 57 -> {66 58}; 58 -> {59}; 59 -> {60}; 60 -> {61}; 61 -> {62}; 62 -> {63}; - 63 -> {70}; + 63 -> {64}; 64 -> {65}; - 65 -> {66}; + 65 -> {72}; 66 -> {67}; 67 -> {68}; 68 -> {69}; @@ -213,65 +218,65 @@ digraph boundSmartcastsInBranches_kt { 71 -> {72}; 72 -> {73}; 73 -> {74}; + 74 -> {75}; + 75 -> {76}; - subgraph cluster_19 { + subgraph cluster_20 { color=red - 75 [label="Enter function test_2" style="filled" fillcolor=red]; - subgraph cluster_20 { + 77 [label="Enter function test_2" style="filled" fillcolor=red]; + subgraph cluster_21 { color=blue - 76 [label="Enter block"]; - 77 [label="Variable declaration: lval x: R|kotlin/Any|"]; - subgraph cluster_21 { + 78 [label="Enter block"]; + 79 [label="Variable declaration: lval x: R|kotlin/Any|"]; + subgraph cluster_22 { color=blue - 78 [label="Enter when"]; - subgraph cluster_22 { - color=blue - 79 [label="Enter when branch condition "]; - 80 [label="Access variable R|/b|"]; - 81 [label="Exit when branch condition"]; - } + 80 [label="Enter when"]; subgraph cluster_23 { color=blue - 82 [label="Enter when branch condition else"]; + 81 [label="Enter when branch condition "]; + 82 [label="Access variable R|/b|"]; 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|/a|"]; - 87 [label="Assignment: R|/x|"]; - 88 [label="Access variable R|/a|"]; - 89 [label="Type operator: (R|/a| as R|A|)"]; - 90 [label="Exit block"]; + 84 [label="Enter when branch condition else"]; + 85 [label="Exit when branch condition"]; } - 91 [label="Exit when branch result"]; - 92 [label="Enter when branch result"]; + 86 [label="Enter when branch result"]; subgraph cluster_25 { color=blue - 93 [label="Enter block"]; - 94 [label="Function call: R|/A.A|()"]; - 95 [label="Assignment: R|/x|"]; - 96 [label="Exit block"]; + 87 [label="Enter block"]; + 88 [label="Access variable R|/a|"]; + 89 [label="Assignment: R|/x|"]; + 90 [label="Access variable R|/a|"]; + 91 [label="Type operator: (R|/a| as R|A|)"]; + 92 [label="Exit block"]; } - 97 [label="Exit when branch result"]; - 98 [label="Exit when"]; + 93 [label="Exit when branch result"]; + 94 [label="Enter when branch result"]; + subgraph cluster_26 { + color=blue + 95 [label="Enter block"]; + 96 [label="Function call: R|/A.A|()"]; + 97 [label="Assignment: R|/x|"]; + 98 [label="Exit block"]; + } + 99 [label="Exit when branch result"]; + 100 [label="Exit when"]; } - 99 [label="Access variable R|/x|"]; - 100 [label="Access variable R|/A.s|"]; - 101 [label="Exit block"]; + 101 [label="Access variable R|/x|"]; + 102 [label="Access variable R|/A.s|"]; + 103 [label="Exit block"]; } - 102 [label="Exit function test_2" style="filled" fillcolor=red]; + 104 [label="Exit function test_2" style="filled" fillcolor=red]; } - 75 -> {76}; - 76 -> {77}; 77 -> {78}; 78 -> {79}; 79 -> {80}; 80 -> {81}; - 81 -> {92 82}; + 81 -> {82}; 82 -> {83}; - 83 -> {84}; + 83 -> {94 84}; 84 -> {85}; 85 -> {86}; 86 -> {87}; @@ -279,9 +284,9 @@ digraph boundSmartcastsInBranches_kt { 88 -> {89}; 89 -> {90}; 90 -> {91}; - 91 -> {98}; + 91 -> {92}; 92 -> {93}; - 93 -> {94}; + 93 -> {100}; 94 -> {95}; 95 -> {96}; 96 -> {97}; @@ -290,65 +295,65 @@ digraph boundSmartcastsInBranches_kt { 99 -> {100}; 100 -> {101}; 101 -> {102}; + 102 -> {103}; + 103 -> {104}; - subgraph cluster_26 { + subgraph cluster_27 { color=red - 103 [label="Enter function test_3" style="filled" fillcolor=red]; - subgraph cluster_27 { + 105 [label="Enter function test_3" style="filled" fillcolor=red]; + subgraph cluster_28 { color=blue - 104 [label="Enter block"]; - 105 [label="Variable declaration: lval x: R|kotlin/Any|"]; - subgraph cluster_28 { + 106 [label="Enter block"]; + 107 [label="Variable declaration: lval x: R|kotlin/Any|"]; + subgraph cluster_29 { color=blue - 106 [label="Enter when"]; - subgraph cluster_29 { - color=blue - 107 [label="Enter when branch condition "]; - 108 [label="Access variable R|/b|"]; - 109 [label="Exit when branch condition"]; - } + 108 [label="Enter when"]; subgraph cluster_30 { color=blue - 110 [label="Enter when branch condition else"]; + 109 [label="Enter when branch condition "]; + 110 [label="Access variable R|/b|"]; 111 [label="Exit when branch condition"]; } - 112 [label="Enter when branch result"]; subgraph cluster_31 { color=blue - 113 [label="Enter block"]; - 114 [label="Access variable R|/a|"]; - 115 [label="Type operator: (R|/a| as R|A|)"]; - 116 [label="Access variable R|/a|"]; - 117 [label="Assignment: R|/x|"]; - 118 [label="Exit block"]; + 112 [label="Enter when branch condition else"]; + 113 [label="Exit when branch condition"]; } - 119 [label="Exit when branch result"]; - 120 [label="Enter when branch result"]; + 114 [label="Enter when branch result"]; subgraph cluster_32 { color=blue - 121 [label="Enter block"]; - 122 [label="Function call: R|/A.A|()"]; - 123 [label="Assignment: R|/x|"]; - 124 [label="Exit block"]; + 115 [label="Enter block"]; + 116 [label="Access variable R|/a|"]; + 117 [label="Type operator: (R|/a| as R|A|)"]; + 118 [label="Access variable R|/a|"]; + 119 [label="Assignment: R|/x|"]; + 120 [label="Exit block"]; } - 125 [label="Exit when branch result"]; - 126 [label="Exit when"]; + 121 [label="Exit when branch result"]; + 122 [label="Enter when branch result"]; + subgraph cluster_33 { + color=blue + 123 [label="Enter block"]; + 124 [label="Function call: R|/A.A|()"]; + 125 [label="Assignment: R|/x|"]; + 126 [label="Exit block"]; + } + 127 [label="Exit when branch result"]; + 128 [label="Exit when"]; } - 127 [label="Access variable R|/x|"]; - 128 [label="Access variable R|/A.s|"]; - 129 [label="Exit block"]; + 129 [label="Access variable R|/x|"]; + 130 [label="Access variable R|/A.s|"]; + 131 [label="Exit block"]; } - 130 [label="Exit function test_3" style="filled" fillcolor=red]; + 132 [label="Exit function test_3" style="filled" fillcolor=red]; } - 103 -> {104}; - 104 -> {105}; 105 -> {106}; 106 -> {107}; 107 -> {108}; 108 -> {109}; - 109 -> {120 110}; + 109 -> {110}; 110 -> {111}; - 111 -> {112}; + 111 -> {122 112}; 112 -> {113}; 113 -> {114}; 114 -> {115}; @@ -356,9 +361,9 @@ digraph boundSmartcastsInBranches_kt { 116 -> {117}; 117 -> {118}; 118 -> {119}; - 119 -> {126}; + 119 -> {120}; 120 -> {121}; - 121 -> {122}; + 121 -> {128}; 122 -> {123}; 123 -> {124}; 124 -> {125}; @@ -367,75 +372,75 @@ digraph boundSmartcastsInBranches_kt { 127 -> {128}; 128 -> {129}; 129 -> {130}; + 130 -> {131}; + 131 -> {132}; - subgraph cluster_33 { + subgraph cluster_34 { color=red - 131 [label="Enter function test_4" style="filled" fillcolor=red]; - subgraph cluster_34 { + 133 [label="Enter function test_4" style="filled" fillcolor=red]; + subgraph cluster_35 { color=blue - 132 [label="Enter block"]; - 133 [label="Variable declaration: lval x: R|kotlin/Any|"]; - subgraph cluster_35 { + 134 [label="Enter block"]; + 135 [label="Variable declaration: lval x: R|kotlin/Any|"]; + subgraph cluster_36 { color=blue - 134 [label="Enter when"]; - subgraph cluster_36 { - color=blue - 135 [label="Enter when branch condition "]; - 136 [label="Access variable R|/b|"]; - 137 [label="Exit when branch condition"]; - } + 136 [label="Enter when"]; subgraph cluster_37 { color=blue - 138 [label="Enter when branch condition else"]; + 137 [label="Enter when branch condition "]; + 138 [label="Access variable R|/b|"]; 139 [label="Exit when branch condition"]; } - 140 [label="Enter when branch result"]; subgraph cluster_38 { color=blue - 141 [label="Enter block"]; - 142 [label="Access variable R|/a|"]; - 143 [label="Assignment: R|/x|"]; - 144 [label="Exit block"]; + 140 [label="Enter when branch condition else"]; + 141 [label="Exit when branch condition"]; } - 145 [label="Exit when branch result"]; - 146 [label="Enter when branch result"]; + 142 [label="Enter when branch result"]; subgraph cluster_39 { color=blue - 147 [label="Enter block"]; - 148 [label="Access variable R|/a|"]; - 149 [label="Assignment: R|/x|"]; - 150 [label="Exit block"]; + 143 [label="Enter block"]; + 144 [label="Access variable R|/a|"]; + 145 [label="Assignment: R|/x|"]; + 146 [label="Exit block"]; } - 151 [label="Exit when branch result"]; - 152 [label="Exit when"]; + 147 [label="Exit when branch result"]; + 148 [label="Enter when branch result"]; + subgraph cluster_40 { + color=blue + 149 [label="Enter block"]; + 150 [label="Access variable R|/a|"]; + 151 [label="Assignment: R|/x|"]; + 152 [label="Exit block"]; + } + 153 [label="Exit when branch result"]; + 154 [label="Exit when"]; } - 153 [label="Access variable R|/x|"]; - 154 [label="Type operator: (R|/x| as R|A|)"]; 155 [label="Access variable R|/x|"]; - 156 [label="Access variable R|/A.s|"]; - 157 [label="Access variable R|/a|"]; + 156 [label="Type operator: (R|/x| as R|A|)"]; + 157 [label="Access variable R|/x|"]; 158 [label="Access variable R|/A.s|"]; - 159 [label="Exit block"]; + 159 [label="Access variable R|/a|"]; + 160 [label="Access variable R|/A.s|"]; + 161 [label="Exit block"]; } - 160 [label="Exit function test_4" style="filled" fillcolor=red]; + 162 [label="Exit function test_4" style="filled" fillcolor=red]; } - 131 -> {132}; - 132 -> {133}; 133 -> {134}; 134 -> {135}; 135 -> {136}; 136 -> {137}; - 137 -> {146 138}; + 137 -> {138}; 138 -> {139}; - 139 -> {140}; + 139 -> {148 140}; 140 -> {141}; 141 -> {142}; 142 -> {143}; 143 -> {144}; 144 -> {145}; - 145 -> {152}; + 145 -> {146}; 146 -> {147}; - 147 -> {148}; + 147 -> {154}; 148 -> {149}; 149 -> {150}; 150 -> {151}; @@ -448,75 +453,75 @@ digraph boundSmartcastsInBranches_kt { 157 -> {158}; 158 -> {159}; 159 -> {160}; + 160 -> {161}; + 161 -> {162}; - subgraph cluster_40 { + subgraph cluster_41 { color=red - 161 [label="Enter function test_5" style="filled" fillcolor=red]; - subgraph cluster_41 { + 163 [label="Enter function test_5" style="filled" fillcolor=red]; + subgraph cluster_42 { color=blue - 162 [label="Enter block"]; - 163 [label="Variable declaration: lval x: R|kotlin/Any|"]; - subgraph cluster_42 { + 164 [label="Enter block"]; + 165 [label="Variable declaration: lval x: R|kotlin/Any|"]; + subgraph cluster_43 { color=blue - 164 [label="Enter when"]; - subgraph cluster_43 { - color=blue - 165 [label="Enter when branch condition "]; - 166 [label="Access variable R|/b|"]; - 167 [label="Exit when branch condition"]; - } + 166 [label="Enter when"]; subgraph cluster_44 { color=blue - 168 [label="Enter when branch condition else"]; + 167 [label="Enter when branch condition "]; + 168 [label="Access variable R|/b|"]; 169 [label="Exit when branch condition"]; } - 170 [label="Enter when branch result"]; subgraph cluster_45 { color=blue - 171 [label="Enter block"]; - 172 [label="Access variable R|/a|"]; - 173 [label="Assignment: R|/x|"]; - 174 [label="Exit block"]; + 170 [label="Enter when branch condition else"]; + 171 [label="Exit when branch condition"]; } - 175 [label="Exit when branch result"]; - 176 [label="Enter when branch result"]; + 172 [label="Enter when branch result"]; subgraph cluster_46 { color=blue - 177 [label="Enter block"]; - 178 [label="Access variable R|/a|"]; - 179 [label="Assignment: R|/x|"]; - 180 [label="Exit block"]; + 173 [label="Enter block"]; + 174 [label="Access variable R|/a|"]; + 175 [label="Assignment: R|/x|"]; + 176 [label="Exit block"]; } - 181 [label="Exit when branch result"]; - 182 [label="Exit when"]; + 177 [label="Exit when branch result"]; + 178 [label="Enter when branch result"]; + subgraph cluster_47 { + color=blue + 179 [label="Enter block"]; + 180 [label="Access variable R|/a|"]; + 181 [label="Assignment: R|/x|"]; + 182 [label="Exit block"]; + } + 183 [label="Exit when branch result"]; + 184 [label="Exit when"]; } - 183 [label="Access variable R|/a|"]; - 184 [label="Type operator: (R|/a| as R|A|)"]; - 185 [label="Access variable R|/x|"]; - 186 [label="Access variable R|/A.s|"]; - 187 [label="Access variable R|/a|"]; + 185 [label="Access variable R|/a|"]; + 186 [label="Type operator: (R|/a| as R|A|)"]; + 187 [label="Access variable R|/x|"]; 188 [label="Access variable R|/A.s|"]; - 189 [label="Exit block"]; + 189 [label="Access variable R|/a|"]; + 190 [label="Access variable R|/A.s|"]; + 191 [label="Exit block"]; } - 190 [label="Exit function test_5" style="filled" fillcolor=red]; + 192 [label="Exit function test_5" style="filled" fillcolor=red]; } - 161 -> {162}; - 162 -> {163}; 163 -> {164}; 164 -> {165}; 165 -> {166}; 166 -> {167}; - 167 -> {176 168}; + 167 -> {168}; 168 -> {169}; - 169 -> {170}; + 169 -> {178 170}; 170 -> {171}; 171 -> {172}; 172 -> {173}; 173 -> {174}; 174 -> {175}; - 175 -> {182}; + 175 -> {176}; 176 -> {177}; - 177 -> {178}; + 177 -> {184}; 178 -> {179}; 179 -> {180}; 180 -> {181}; @@ -529,213 +534,213 @@ digraph boundSmartcastsInBranches_kt { 187 -> {188}; 188 -> {189}; 189 -> {190}; - - subgraph cluster_47 { - color=red - 191 [label="Enter function test_6" style="filled" fillcolor=red]; - subgraph cluster_48 { - color=blue - 192 [label="Enter block"]; - 193 [label="Variable declaration: lval x: R|kotlin/Any|"]; - 194 [label="Access variable R|/a|"]; - 195 [label="Assignment: R|/x|"]; - 196 [label="Access variable R|/x|"]; - 197 [label="Access variable R|/A.s|"]; - 198 [label="Exit block"]; - } - 199 [label="Exit function test_6" style="filled" fillcolor=red]; - } + 190 -> {191}; 191 -> {192}; - 192 -> {193}; + + subgraph cluster_48 { + color=red + 193 [label="Enter function test_6" style="filled" fillcolor=red]; + subgraph cluster_49 { + color=blue + 194 [label="Enter block"]; + 195 [label="Variable declaration: lval x: R|kotlin/Any|"]; + 196 [label="Access variable R|/a|"]; + 197 [label="Assignment: R|/x|"]; + 198 [label="Access variable R|/x|"]; + 199 [label="Access variable R|/A.s|"]; + 200 [label="Exit block"]; + } + 201 [label="Exit function test_6" style="filled" fillcolor=red]; + } 193 -> {194}; 194 -> {195}; 195 -> {196}; 196 -> {197}; 197 -> {198}; 198 -> {199}; + 199 -> {200}; + 200 -> {201}; - subgraph cluster_49 { + subgraph cluster_50 { color=red - 200 [label="Enter function test_7" style="filled" fillcolor=red]; - subgraph cluster_50 { + 202 [label="Enter function test_7" style="filled" fillcolor=red]; + subgraph cluster_51 { color=blue - 201 [label="Enter block"]; - 202 [label="Const: Null(null)"]; - 203 [label="Variable declaration: lval z: R|kotlin/String?|"]; - 204 [label="Access variable R|/z|"]; - 205 [label="Variable declaration: lvar y: R|kotlin/String?|"]; - 206 [label="Access variable R|/y|"]; - 207 [label="Variable declaration: lval x: R|kotlin/String?|"]; - subgraph cluster_51 { + 203 [label="Enter block"]; + 204 [label="Const: Null(null)"]; + 205 [label="Variable declaration: lval z: R|kotlin/String?|"]; + 206 [label="Access variable R|/z|"]; + 207 [label="Variable declaration: lvar y: R|kotlin/String?|"]; + 208 [label="Access variable R|/y|"]; + 209 [label="Variable declaration: lval x: R|kotlin/String?|"]; + subgraph cluster_52 { color=blue - 208 [label="Enter when"]; - subgraph cluster_52 { - color=blue - 209 [label="Enter when branch condition "]; - 210 [label="Access variable R|/x|"]; - 211 [label="Const: Null(null)"]; - 212 [label="Equality operator !="]; - 213 [label="Exit when branch condition"]; - } - 214 [label="Synthetic else branch"]; - 215 [label="Enter when branch result"]; + 210 [label="Enter when"]; subgraph cluster_53 { color=blue - 216 [label="Enter block"]; - 217 [label="Access variable R|/x|"]; - 218 [label="Access variable R|kotlin/String.length|"]; - 219 [label="Access variable R|/y|"]; - 220 [label="Access variable R|kotlin/String.length|"]; - 221 [label="Access variable R|/z|"]; - 222 [label="Access variable R|kotlin/String.length|"]; - 223 [label="Exit block"]; + 211 [label="Enter when branch condition "]; + 212 [label="Access variable R|/x|"]; + 213 [label="Const: Null(null)"]; + 214 [label="Equality operator !="]; + 215 [label="Exit when branch condition"]; } - 224 [label="Exit when branch result"]; - 225 [label="Exit when"]; - } - subgraph cluster_54 { - color=blue - 226 [label="Enter when"]; - subgraph cluster_55 { + 216 [label="Synthetic else branch"]; + 217 [label="Enter when branch result"]; + subgraph cluster_54 { color=blue - 227 [label="Enter when branch condition "]; - 228 [label="Access variable R|/y|"]; - 229 [label="Const: Null(null)"]; - 230 [label="Equality operator !="]; - 231 [label="Exit when branch condition"]; + 218 [label="Enter block"]; + 219 [label="Access variable R|/x|"]; + 220 [label="Access variable R|kotlin/String.length|"]; + 221 [label="Access variable R|/y|"]; + 222 [label="Access variable R|kotlin/String.length|"]; + 223 [label="Access variable R|/z|"]; + 224 [label="Access variable R|kotlin/String.length|"]; + 225 [label="Exit block"]; } - 232 [label="Synthetic else branch"]; - 233 [label="Enter when branch result"]; + 226 [label="Exit when branch result"]; + 227 [label="Exit when"]; + } + subgraph cluster_55 { + color=blue + 228 [label="Enter when"]; subgraph cluster_56 { color=blue - 234 [label="Enter block"]; - 235 [label="Access variable R|/x|"]; - 236 [label="Access variable R|kotlin/String.length|"]; - 237 [label="Access variable R|/y|"]; - 238 [label="Access variable R|kotlin/String.length|"]; - 239 [label="Access variable R|/z|"]; - 240 [label="Access variable R|kotlin/String.length|"]; - 241 [label="Exit block"]; + 229 [label="Enter when branch condition "]; + 230 [label="Access variable R|/y|"]; + 231 [label="Const: Null(null)"]; + 232 [label="Equality operator !="]; + 233 [label="Exit when branch condition"]; } - 242 [label="Exit when branch result"]; - 243 [label="Exit when"]; - } - subgraph cluster_57 { - color=blue - 244 [label="Enter when"]; - subgraph cluster_58 { + 234 [label="Synthetic else branch"]; + 235 [label="Enter when branch result"]; + subgraph cluster_57 { color=blue - 245 [label="Enter when branch condition "]; - 246 [label="Access variable R|/z|"]; - 247 [label="Const: Null(null)"]; - 248 [label="Equality operator !="]; - 249 [label="Exit when branch condition"]; + 236 [label="Enter block"]; + 237 [label="Access variable R|/x|"]; + 238 [label="Access variable R|kotlin/String.length|"]; + 239 [label="Access variable R|/y|"]; + 240 [label="Access variable R|kotlin/String.length|"]; + 241 [label="Access variable R|/z|"]; + 242 [label="Access variable R|kotlin/String.length|"]; + 243 [label="Exit block"]; } - 250 [label="Synthetic else branch"]; - 251 [label="Enter when branch result"]; + 244 [label="Exit when branch result"]; + 245 [label="Exit when"]; + } + subgraph cluster_58 { + color=blue + 246 [label="Enter when"]; subgraph cluster_59 { color=blue - 252 [label="Enter block"]; - 253 [label="Access variable R|/x|"]; - 254 [label="Access variable R|kotlin/String.length|"]; - 255 [label="Access variable R|/y|"]; - 256 [label="Access variable R|kotlin/String.length|"]; - 257 [label="Access variable R|/z|"]; - 258 [label="Access variable R|kotlin/String.length|"]; - 259 [label="Exit block"]; + 247 [label="Enter when branch condition "]; + 248 [label="Access variable R|/z|"]; + 249 [label="Const: Null(null)"]; + 250 [label="Equality operator !="]; + 251 [label="Exit when branch condition"]; } - 260 [label="Exit when branch result"]; - 261 [label="Exit when"]; - } - 262 [label="Const: Null(null)"]; - 263 [label="Assignment: R|/y|"]; - subgraph cluster_60 { - color=blue - 264 [label="Enter when"]; - subgraph cluster_61 { + 252 [label="Synthetic else branch"]; + 253 [label="Enter when branch result"]; + subgraph cluster_60 { color=blue - 265 [label="Enter when branch condition "]; - 266 [label="Access variable R|/x|"]; - 267 [label="Const: Null(null)"]; - 268 [label="Equality operator !="]; - 269 [label="Exit when branch condition"]; + 254 [label="Enter block"]; + 255 [label="Access variable R|/x|"]; + 256 [label="Access variable R|kotlin/String.length|"]; + 257 [label="Access variable R|/y|"]; + 258 [label="Access variable R|kotlin/String.length|"]; + 259 [label="Access variable R|/z|"]; + 260 [label="Access variable R|kotlin/String.length|"]; + 261 [label="Exit block"]; } - 270 [label="Synthetic else branch"]; - 271 [label="Enter when branch result"]; + 262 [label="Exit when branch result"]; + 263 [label="Exit when"]; + } + 264 [label="Const: Null(null)"]; + 265 [label="Assignment: R|/y|"]; + subgraph cluster_61 { + color=blue + 266 [label="Enter when"]; subgraph cluster_62 { color=blue - 272 [label="Enter block"]; - 273 [label="Access variable R|/x|"]; - 274 [label="Access variable R|kotlin/String.length|"]; - 275 [label="Access variable R|/y|"]; - 276 [label="Access variable #"]; - 277 [label="Access variable R|/z|"]; - 278 [label="Access variable R|kotlin/String.length|"]; - 279 [label="Exit block"]; + 267 [label="Enter when branch condition "]; + 268 [label="Access variable R|/x|"]; + 269 [label="Const: Null(null)"]; + 270 [label="Equality operator !="]; + 271 [label="Exit when branch condition"]; } - 280 [label="Exit when branch result"]; - 281 [label="Exit when"]; - } - subgraph cluster_63 { - color=blue - 282 [label="Enter when"]; - subgraph cluster_64 { + 272 [label="Synthetic else branch"]; + 273 [label="Enter when branch result"]; + subgraph cluster_63 { color=blue - 283 [label="Enter when branch condition "]; - 284 [label="Access variable R|/y|"]; - 285 [label="Const: Null(null)"]; - 286 [label="Equality operator !="]; - 287 [label="Exit when branch condition"]; + 274 [label="Enter block"]; + 275 [label="Access variable R|/x|"]; + 276 [label="Access variable R|kotlin/String.length|"]; + 277 [label="Access variable R|/y|"]; + 278 [label="Access variable #"]; + 279 [label="Access variable R|/z|"]; + 280 [label="Access variable R|kotlin/String.length|"]; + 281 [label="Exit block"]; } - 288 [label="Synthetic else branch"]; - 289 [label="Enter when branch result"]; + 282 [label="Exit when branch result"]; + 283 [label="Exit when"]; + } + subgraph cluster_64 { + color=blue + 284 [label="Enter when"]; subgraph cluster_65 { color=blue - 290 [label="Enter block"]; - 291 [label="Access variable R|/x|"]; - 292 [label="Access variable #"]; - 293 [label="Access variable R|/y|"]; - 294 [label="Access variable R|kotlin/String.length|"]; - 295 [label="Access variable R|/z|"]; - 296 [label="Access variable #"]; - 297 [label="Exit block"]; + 285 [label="Enter when branch condition "]; + 286 [label="Access variable R|/y|"]; + 287 [label="Const: Null(null)"]; + 288 [label="Equality operator !="]; + 289 [label="Exit when branch condition"]; } - 298 [label="Exit when branch result"]; - 299 [label="Exit when"]; - } - subgraph cluster_66 { - color=blue - 300 [label="Enter when"]; - subgraph cluster_67 { + 290 [label="Synthetic else branch"]; + 291 [label="Enter when branch result"]; + subgraph cluster_66 { color=blue - 301 [label="Enter when branch condition "]; - 302 [label="Access variable R|/z|"]; - 303 [label="Const: Null(null)"]; - 304 [label="Equality operator !="]; - 305 [label="Exit when branch condition"]; + 292 [label="Enter block"]; + 293 [label="Access variable R|/x|"]; + 294 [label="Access variable #"]; + 295 [label="Access variable R|/y|"]; + 296 [label="Access variable R|kotlin/String.length|"]; + 297 [label="Access variable R|/z|"]; + 298 [label="Access variable #"]; + 299 [label="Exit block"]; } - 306 [label="Synthetic else branch"]; - 307 [label="Enter when branch result"]; + 300 [label="Exit when branch result"]; + 301 [label="Exit when"]; + } + subgraph cluster_67 { + color=blue + 302 [label="Enter when"]; subgraph cluster_68 { color=blue - 308 [label="Enter block"]; - 309 [label="Access variable R|/x|"]; - 310 [label="Access variable R|kotlin/String.length|"]; - 311 [label="Access variable R|/y|"]; - 312 [label="Access variable #"]; - 313 [label="Access variable R|/z|"]; - 314 [label="Access variable R|kotlin/String.length|"]; - 315 [label="Exit block"]; + 303 [label="Enter when branch condition "]; + 304 [label="Access variable R|/z|"]; + 305 [label="Const: Null(null)"]; + 306 [label="Equality operator !="]; + 307 [label="Exit when branch condition"]; } - 316 [label="Exit when branch result"]; - 317 [label="Exit when"]; + 308 [label="Synthetic else branch"]; + 309 [label="Enter when branch result"]; + subgraph cluster_69 { + color=blue + 310 [label="Enter block"]; + 311 [label="Access variable R|/x|"]; + 312 [label="Access variable R|kotlin/String.length|"]; + 313 [label="Access variable R|/y|"]; + 314 [label="Access variable #"]; + 315 [label="Access variable R|/z|"]; + 316 [label="Access variable R|kotlin/String.length|"]; + 317 [label="Exit block"]; + } + 318 [label="Exit when branch result"]; + 319 [label="Exit when"]; } - 318 [label="Exit block"]; + 320 [label="Exit block"]; } - 319 [label="Exit function test_7" style="filled" fillcolor=red]; + 321 [label="Exit function test_7" style="filled" fillcolor=red]; } - 200 -> {201}; - 201 -> {202}; 202 -> {203}; 203 -> {204}; 204 -> {205}; @@ -747,10 +752,10 @@ digraph boundSmartcastsInBranches_kt { 210 -> {211}; 211 -> {212}; 212 -> {213}; - 213 -> {215 214}; - 214 -> {225}; - 215 -> {216}; - 216 -> {217}; + 213 -> {214}; + 214 -> {215}; + 215 -> {217 216}; + 216 -> {227}; 217 -> {218}; 218 -> {219}; 219 -> {220}; @@ -765,10 +770,10 @@ digraph boundSmartcastsInBranches_kt { 228 -> {229}; 229 -> {230}; 230 -> {231}; - 231 -> {233 232}; - 232 -> {243}; - 233 -> {234}; - 234 -> {235}; + 231 -> {232}; + 232 -> {233}; + 233 -> {235 234}; + 234 -> {245}; 235 -> {236}; 236 -> {237}; 237 -> {238}; @@ -783,10 +788,10 @@ digraph boundSmartcastsInBranches_kt { 246 -> {247}; 247 -> {248}; 248 -> {249}; - 249 -> {251 250}; - 250 -> {261}; - 251 -> {252}; - 252 -> {253}; + 249 -> {250}; + 250 -> {251}; + 251 -> {253 252}; + 252 -> {263}; 253 -> {254}; 254 -> {255}; 255 -> {256}; @@ -803,10 +808,10 @@ digraph boundSmartcastsInBranches_kt { 266 -> {267}; 267 -> {268}; 268 -> {269}; - 269 -> {271 270}; - 270 -> {281}; - 271 -> {272}; - 272 -> {273}; + 269 -> {270}; + 270 -> {271}; + 271 -> {273 272}; + 272 -> {283}; 273 -> {274}; 274 -> {275}; 275 -> {276}; @@ -821,10 +826,10 @@ digraph boundSmartcastsInBranches_kt { 284 -> {285}; 285 -> {286}; 286 -> {287}; - 287 -> {289 288}; - 288 -> {299}; - 289 -> {290}; - 290 -> {291}; + 287 -> {288}; + 288 -> {289}; + 289 -> {291 290}; + 290 -> {301}; 291 -> {292}; 292 -> {293}; 293 -> {294}; @@ -839,10 +844,10 @@ digraph boundSmartcastsInBranches_kt { 302 -> {303}; 303 -> {304}; 304 -> {305}; - 305 -> {307 306}; - 306 -> {317}; - 307 -> {308}; - 308 -> {309}; + 305 -> {306}; + 306 -> {307}; + 307 -> {309 308}; + 308 -> {319}; 309 -> {310}; 310 -> {311}; 311 -> {312}; @@ -853,5 +858,7 @@ digraph boundSmartcastsInBranches_kt { 316 -> {317}; 317 -> {318}; 318 -> {319}; + 319 -> {320}; + 320 -> {321}; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.fir.txt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.fir.txt index 789fa0ae7b8..a30cce4290b 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.fir.txt @@ -10,17 +10,20 @@ FILE: boundSmartcastsInBranches.kt } public final fun test_0(list: R|kotlin/collections/List|): R|kotlin/Unit| { lvar goodA: R|A?| = Null(null) - lval : R|kotlin/collections/Iterator| = R|/list|.R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval a: R|A| = R|/|.R|SubstitutionOverride|() - when () { - ==(R|/goodA|, Null(null)) -> { - R|/goodA| = R|/a| - continue@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] + { + lval : R|kotlin/collections/Iterator| = R|/list|.R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval a: R|A| = R|/|.R|SubstitutionOverride|() + when () { + ==(R|/goodA|, Null(null)) -> { + R|/goodA| = R|/a| + continue@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] + } } + + R|/goodA|.R|/A.s| } - R|/goodA|.R|/A.s| } } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot index d658facab69..49d3defc142 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot @@ -166,83 +166,88 @@ digraph smartcastToNothing_kt { 52 [label="Enter block"]; 53 [label="Const: Null(null)"]; 54 [label="Variable declaration: lvar s: R|A?|"]; - 55 [label="Access variable R|/results|"]; - 56 [label="Function call: R|/results|.R|SubstitutionOverride|>|()"]; - 57 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; subgraph cluster_16 { color=blue - 58 [label="Enter while loop"]; + 55 [label="Enter block"]; + 56 [label="Access variable R|/results|"]; + 57 [label="Function call: R|/results|.R|SubstitutionOverride|>|()"]; + 58 [label="Variable declaration: lval : R|kotlin/collections/Iterator|"]; subgraph cluster_17 { color=blue - 59 [label="Enter loop condition"]; - 60 [label="Access variable R|/|"]; - 61 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; - 62 [label="Exit loop condition"]; - } - subgraph cluster_18 { - color=blue - 63 [label="Enter loop block"]; + 59 [label="Enter while loop"]; + subgraph cluster_18 { + color=blue + 60 [label="Enter loop condition"]; + 61 [label="Access variable R|/|"]; + 62 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; + 63 [label="Exit loop condition"]; + } subgraph cluster_19 { color=blue - 64 [label="Enter block"]; - 65 [label="Access variable R|/|"]; - 66 [label="Function call: R|/|.R|SubstitutionOverride|()"]; - 67 [label="Stub" style="filled" fillcolor=gray]; - 68 [label="Variable declaration: lval result: R|kotlin/Nothing|" style="filled" fillcolor=gray]; - 69 [label="Access variable R|/result|" style="filled" fillcolor=gray]; - 70 [label="Stub" style="filled" fillcolor=gray]; - 71 [label="Assignment: R|/s|" style="filled" fillcolor=gray]; + 64 [label="Enter loop block"]; subgraph cluster_20 { color=blue - 72 [label="Enter when" style="filled" fillcolor=gray]; + 65 [label="Enter block"]; + 66 [label="Access variable R|/|"]; + 67 [label="Function call: R|/|.R|SubstitutionOverride|()"]; + 68 [label="Stub" style="filled" fillcolor=gray]; + 69 [label="Variable declaration: lval result: R|kotlin/Nothing|" style="filled" fillcolor=gray]; + 70 [label="Access variable R|/result|" style="filled" fillcolor=gray]; + 71 [label="Stub" style="filled" fillcolor=gray]; + 72 [label="Assignment: R|/s|" style="filled" fillcolor=gray]; subgraph cluster_21 { color=blue - 73 [label="Enter when branch condition " style="filled" fillcolor=gray]; - 74 [label="Access variable R|/result|" style="filled" fillcolor=gray]; - 75 [label="Stub" style="filled" fillcolor=gray]; - 76 [label="Access variable #" style="filled" fillcolor=gray]; - 77 [label="Exit when branch condition" style="filled" fillcolor=gray]; + 73 [label="Enter when" style="filled" fillcolor=gray]; + subgraph cluster_22 { + color=blue + 74 [label="Enter when branch condition " style="filled" fillcolor=gray]; + 75 [label="Access variable R|/result|" style="filled" fillcolor=gray]; + 76 [label="Stub" style="filled" fillcolor=gray]; + 77 [label="Access variable #" style="filled" fillcolor=gray]; + 78 [label="Exit when branch condition" style="filled" fillcolor=gray]; + } + 79 [label="Synthetic else branch" style="filled" fillcolor=gray]; + 80 [label="Enter when branch result" style="filled" fillcolor=gray]; + subgraph cluster_23 { + color=blue + 81 [label="Enter block" style="filled" fillcolor=gray]; + 82 [label="Jump: break@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] " style="filled" fillcolor=gray]; + 83 [label="Stub" style="filled" fillcolor=gray]; + 84 [label="Exit block" style="filled" fillcolor=gray]; + } + 85 [label="Exit when branch result" style="filled" fillcolor=gray]; + 86 [label="Exit when" style="filled" fillcolor=gray]; } - 78 [label="Synthetic else branch" style="filled" fillcolor=gray]; - 79 [label="Enter when branch result" style="filled" fillcolor=gray]; - subgraph cluster_22 { - color=blue - 80 [label="Enter block" style="filled" fillcolor=gray]; - 81 [label="Jump: break@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] " style="filled" fillcolor=gray]; - 82 [label="Stub" style="filled" fillcolor=gray]; - 83 [label="Exit block" style="filled" fillcolor=gray]; - } - 84 [label="Exit when branch result" style="filled" fillcolor=gray]; - 85 [label="Exit when" style="filled" fillcolor=gray]; + 87 [label="Exit block" style="filled" fillcolor=gray]; } - 86 [label="Exit block" style="filled" fillcolor=gray]; + 88 [label="Exit loop block" style="filled" fillcolor=gray]; } - 87 [label="Exit loop block" style="filled" fillcolor=gray]; + 89 [label="Exit whileloop"]; } - 88 [label="Exit whileloop"]; + 90 [label="Exit block"]; } - 89 [label="Access variable R|/s|"]; - 90 [label="Enter safe call"]; - 91 [label="Postponed enter to lambda"]; - subgraph cluster_23 { + 91 [label="Access variable R|/s|"]; + 92 [label="Enter safe call"]; + 93 [label="Postponed enter to lambda"]; + subgraph cluster_24 { color=blue - 98 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; - subgraph cluster_24 { + 100 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + subgraph cluster_25 { color=blue - 99 [label="Enter block"]; - 100 [label="Access variable R|/it|"]; - 101 [label="Access variable R|/A.a|"]; - 102 [label="Exit block"]; + 101 [label="Enter block"]; + 102 [label="Access variable R|/it|"]; + 103 [label="Access variable R|/A.a|"]; + 104 [label="Exit block"]; } - 103 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 105 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } - 92 [label="Call arguments union" style="filled" fillcolor=yellow]; - 93 [label="Postponed exit from lambda"]; - 94 [label="Function call: $subj$.R|kotlin/let|(...)"]; - 95 [label="Exit safe call"]; - 96 [label="Exit block"]; + 94 [label="Call arguments union" style="filled" fillcolor=yellow]; + 95 [label="Postponed exit from lambda"]; + 96 [label="Function call: $subj$.R|kotlin/let|(...)"]; + 97 [label="Exit safe call"]; + 98 [label="Exit block"]; } - 97 [label="Exit function test_0" style="filled" fillcolor=red]; + 99 [label="Exit function test_0" style="filled" fillcolor=red]; } 51 -> {52}; 52 -> {53}; @@ -255,52 +260,54 @@ digraph smartcastToNothing_kt { 59 -> {60}; 60 -> {61}; 61 -> {62}; - 62 -> {88 63}; - 63 -> {64}; + 62 -> {63}; + 63 -> {89 64}; 64 -> {65}; 65 -> {66}; - 66 -> {97} [label=onUncaughtException]; - 66 -> {67} [style=dotted]; + 66 -> {67}; + 67 -> {99} [label=onUncaughtException]; 67 -> {68} [style=dotted]; 68 -> {69} [style=dotted]; 69 -> {70} [style=dotted]; - 69 -> {97} [style=dotted] [label=onUncaughtException]; 70 -> {71} [style=dotted]; + 70 -> {99} [style=dotted] [label=onUncaughtException]; 71 -> {72} [style=dotted]; 72 -> {73} [style=dotted]; 73 -> {74} [style=dotted]; 74 -> {75} [style=dotted]; - 74 -> {97} [style=dotted] [label=onUncaughtException]; 75 -> {76} [style=dotted]; + 75 -> {99} [style=dotted] [label=onUncaughtException]; 76 -> {77} [style=dotted]; - 77 -> {79 78} [style=dotted]; - 78 -> {85} [style=dotted]; - 79 -> {80} [style=dotted]; + 77 -> {78} [style=dotted]; + 78 -> {80 79} [style=dotted]; + 79 -> {86} [style=dotted]; 80 -> {81} [style=dotted]; - 81 -> {88 82} [style=dotted]; - 82 -> {83} [style=dotted]; + 81 -> {82} [style=dotted]; + 82 -> {89 83} [style=dotted]; 83 -> {84} [style=dotted]; 84 -> {85} [style=dotted]; 85 -> {86} [style=dotted]; 86 -> {87} [style=dotted]; - 87 -> {59} [color=green style=dotted]; - 88 -> {89}; - 89 -> {90 95}; + 87 -> {88} [style=dotted]; + 88 -> {60} [color=green style=dotted]; + 89 -> {90}; 90 -> {91}; - 91 -> {98}; - 91 -> {93} [color=red]; - 91 -> {98} [style=dashed]; - 92 -> {94} [color=red]; - 93 -> {94} [color=green]; - 94 -> {95}; - 95 -> {96}; + 91 -> {92 97}; + 92 -> {93}; + 93 -> {100}; + 93 -> {95} [color=red]; + 93 -> {100} [style=dashed]; + 94 -> {96} [color=red]; + 95 -> {96} [color=green]; 96 -> {97}; + 97 -> {98}; 98 -> {99}; - 99 -> {100}; 100 -> {101}; 101 -> {102}; 102 -> {103}; - 103 -> {92} [color=red]; - 103 -> {93} [color=green]; + 103 -> {104}; + 104 -> {105}; + 105 -> {94} [color=red]; + 105 -> {95} [color=green]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt index 23d5348e8f7..0203f55d12a 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.fir.txt @@ -30,14 +30,17 @@ FILE: smartcastToNothing.kt } public final fun test_0(results: R|kotlin/collections/List|): R|kotlin/Unit| { lvar s: R|A?| = Null(null) - lval : R|kotlin/collections/Iterator| = R|/results|.R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval result: R|kotlin/Nothing| = R|/|.R|SubstitutionOverride|() - R|/s| = R|/result| - when () { - R|/result|.# -> { - break@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] + { + lval : R|kotlin/collections/Iterator| = R|/results|.R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval result: R|kotlin/Nothing| = R|/|.R|SubstitutionOverride|() + R|/s| = R|/result| + when () { + R|/result|.# -> { + break@@@[R|/|.R|kotlin/collections/Iterator.hasNext|()] + } } + } } diff --git a/compiler/fir/analysis-tests/testData/resolve/varargInPrimaryConstructor.fir.txt b/compiler/fir/analysis-tests/testData/resolve/varargInPrimaryConstructor.fir.txt index d8259c694dd..cec089770f6 100644 --- a/compiler/fir/analysis-tests/testData/resolve/varargInPrimaryConstructor.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/varargInPrimaryConstructor.fir.txt @@ -9,18 +9,24 @@ FILE: varargInPrimaryConstructor.kt } public final fun test_1(foo: R|Foo|): R|kotlin/Unit| { - lval : R|kotlin/collections/Iterator| = R|/foo|.R|/Foo.strings|.R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval s: R|kotlin/String| = R|/|.R|SubstitutionOverride|() - R|/s|.R|kotlin/String.length| + { + lval : R|kotlin/collections/Iterator| = R|/foo|.R|/Foo.strings|.R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval s: R|kotlin/String| = R|/|.R|SubstitutionOverride|() + R|/s|.R|kotlin/String.length| + } + } } public final fun test_2(vararg strings: R|kotlin/Array|): R|kotlin/Unit| { - lval : R|kotlin/collections/Iterator| = R|/strings|.R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval s: R|kotlin/String| = R|/|.R|SubstitutionOverride|() - R|/s|.R|kotlin/String.length| + { + lval : R|kotlin/collections/Iterator| = R|/strings|.R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval s: R|kotlin/String| = R|/|.R|SubstitutionOverride|() + R|/s|.R|kotlin/String.length| + } + } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/components.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/components.fir.txt index 08fb6aae8b6..9d05d6714c2 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/components.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/components.fir.txt @@ -18,11 +18,14 @@ FILE: components.kt } public final fun foo(list: R|kotlin/collections/List|): R|kotlin/Unit| { - lval : R|kotlin/collections/Iterator| = R|/list|.R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval : R|D| = R|/|.R|SubstitutionOverride|() - lval x: R|kotlin/Int| = R|/|.R|/D.component1|() - lval y: R|kotlin/String| = R|/|.R|/D.component2|() + { + lval : R|kotlin/collections/Iterator| = R|/list|.R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval : R|D| = R|/|.R|SubstitutionOverride|() + lval x: R|kotlin/Int| = R|/|.R|/D.component1|() + lval y: R|kotlin/String| = R|/|.R|/D.component2|() + } + } lval : R|D| = R|/list|.R|kotlin/collections/first|() diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.dot index 3554770866a..fe8d960eecd 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.dot @@ -128,71 +128,76 @@ digraph flow_kt { subgraph cluster_16 { color=blue 56 [label="Enter block"]; - 57 [label="Const: Int(0)"]; - 58 [label="Const: Int(0)"]; - 59 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...)"]; - 60 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...).R|kotlin/ranges/IntProgression.iterator|()"]; - 61 [label="Variable declaration: lval : R|kotlin/collections/IntIterator|"]; subgraph cluster_17 { color=blue - 62 [label="Enter while loop"]; + 57 [label="Enter block"]; + 58 [label="Const: Int(0)"]; + 59 [label="Const: Int(0)"]; + 60 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...)"]; + 61 [label="Function call: Int(0).R|kotlin/Int.rangeTo|(...).R|kotlin/ranges/IntProgression.iterator|()"]; + 62 [label="Variable declaration: lval : R|kotlin/collections/IntIterator|"]; subgraph cluster_18 { color=blue - 63 [label="Enter loop condition"]; - 64 [label="Access variable R|/|"]; - 65 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; - 66 [label="Exit loop condition"]; - } - subgraph cluster_19 { - color=blue - 67 [label="Enter loop block"]; + 63 [label="Enter while loop"]; + subgraph cluster_19 { + color=blue + 64 [label="Enter loop condition"]; + 65 [label="Access variable R|/|"]; + 66 [label="Function call: R|/|.R|kotlin/collections/Iterator.hasNext|()"]; + 67 [label="Exit loop condition"]; + } subgraph cluster_20 { color=blue - 68 [label="Enter block"]; - 69 [label="Access variable R|/|"]; - 70 [label="Function call: R|/|.R|kotlin/collections/IntIterator.next|()"]; - 71 [label="Variable declaration: lval i: R|kotlin/Int|"]; - 72 [label="Access variable R|/x|"]; - 73 [label="Function call: R|/x|.R|SubstitutionOverride|()"]; - 74 [label="Exit block"]; + 68 [label="Enter loop block"]; + subgraph cluster_21 { + color=blue + 69 [label="Enter block"]; + 70 [label="Access variable R|/|"]; + 71 [label="Function call: R|/|.R|kotlin/collections/IntIterator.next|()"]; + 72 [label="Variable declaration: lval i: R|kotlin/Int|"]; + 73 [label="Access variable R|/x|"]; + 74 [label="Function call: R|/x|.R|SubstitutionOverride|()"]; + 75 [label="Exit block"]; + } + 76 [label="Exit loop block"]; } - 75 [label="Exit loop block"]; + 77 [label="Exit whileloop"]; } - 76 [label="Exit whileloop"]; + 78 [label="Exit block"]; } - 77 [label="Access variable R|/y|"]; - 78 [label="Function call: R|/y|.R|SubstitutionOverride|()"]; - 79 [label="Exit block"]; + 79 [label="Access variable R|/y|"]; + 80 [label="Function call: R|/y|.R|SubstitutionOverride|()"]; + 81 [label="Exit block"]; } - 80 [label="Exit when branch result"]; - 81 [label="Exit when"]; + 82 [label="Exit when branch result"]; + 83 [label="Exit when"]; } - subgraph cluster_21 { + subgraph cluster_22 { color=blue - 82 [label="Enter do-while loop"]; - subgraph cluster_22 { + 84 [label="Enter do-while loop"]; + subgraph cluster_23 { color=blue - 83 [label="Enter loop block"]; - subgraph cluster_23 { + 85 [label="Enter loop block"]; + subgraph cluster_24 { color=blue - 84 [label="Enter block"]; - 85 [label="Access variable R|/z|"]; - 86 [label="Function call: R|/bar|(...)"]; - 87 [label="Exit block"]; + 86 [label="Enter block"]; + 87 [label="Access variable R|/z|"]; + 88 [label="Function call: R|/bar|(...)"]; + 89 [label="Exit block"]; } - 88 [label="Exit loop block"]; + 90 [label="Exit loop block"]; } - subgraph cluster_24 { + subgraph cluster_25 { color=blue - 89 [label="Enter loop condition"]; - 90 [label="Const: Boolean(true)"]; - 91 [label="Exit loop condition"]; + 91 [label="Enter loop condition"]; + 92 [label="Const: Boolean(true)"]; + 93 [label="Exit loop condition"]; } - 92 [label="Exit do-whileloop" style="filled" fillcolor=gray]; + 94 [label="Exit do-whileloop" style="filled" fillcolor=gray]; } - 93 [label="Exit block" style="filled" fillcolor=gray]; + 95 [label="Exit block" style="filled" fillcolor=gray]; } - 94 [label="Exit function foo" style="filled" fillcolor=red]; + 96 [label="Exit function foo" style="filled" fillcolor=red]; } 20 -> {21}; 21 -> {22}; @@ -216,7 +221,7 @@ digraph flow_kt { 39 -> {40}; 40 -> {41}; 41 -> {42}; - 42 -> {94}; + 42 -> {96}; 42 -> {43} [style=dotted]; 43 -> {44} [style=dotted]; 44 -> {45} [style=dotted]; @@ -229,7 +234,7 @@ digraph flow_kt { 51 -> {52}; 52 -> {53}; 53 -> {54}; - 54 -> {81}; + 54 -> {83}; 55 -> {56}; 56 -> {57}; 57 -> {58}; @@ -241,8 +246,8 @@ digraph flow_kt { 63 -> {64}; 64 -> {65}; 65 -> {66}; - 66 -> {76 67}; - 67 -> {68}; + 66 -> {67}; + 67 -> {77 68}; 68 -> {69}; 69 -> {70}; 70 -> {71}; @@ -250,8 +255,8 @@ digraph flow_kt { 72 -> {73}; 73 -> {74}; 74 -> {75}; - 75 -> {63} [color=green style=dashed]; - 76 -> {77}; + 75 -> {76}; + 76 -> {64} [color=green style=dashed]; 77 -> {78}; 78 -> {79}; 79 -> {80}; @@ -266,9 +271,11 @@ digraph flow_kt { 88 -> {89}; 89 -> {90}; 90 -> {91}; - 91 -> {92} [style=dotted]; - 91 -> {83} [color=green style=dashed]; - 92 -> {93} [style=dotted]; + 91 -> {92}; + 92 -> {93}; 93 -> {94} [style=dotted]; + 93 -> {85} [color=green style=dashed]; + 94 -> {95} [style=dotted]; + 95 -> {96} [style=dotted]; } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.fir.txt index 53a24a6592c..cbe5e4e0904 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/good/callsInPlace/flow.fir.txt @@ -26,10 +26,13 @@ FILE: flow.kt [StubStatement] when () { Boolean(true) -> { - lval : R|kotlin/collections/IntIterator| = Int(0).R|kotlin/Int.rangeTo|(Int(0)).R|kotlin/ranges/IntProgression.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() - R|/x|.R|SubstitutionOverride|() + { + lval : R|kotlin/collections/IntIterator| = Int(0).R|kotlin/Int.rangeTo|(Int(0)).R|kotlin/ranges/IntProgression.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|kotlin/collections/IntIterator.next|() + R|/x|.R|SubstitutionOverride|() + } + } R|/y|.R|SubstitutionOverride|() diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/forLoopChecker.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/forLoopChecker.fir.txt index a6e1f2b28ca..5dabdedd587 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/forLoopChecker.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/forLoopChecker.fir.txt @@ -171,59 +171,92 @@ FILE: forLoopChecker.kt } public final fun test(notRange1: R|NotRange1|, notRange2: R|NotRange2|, notRange3: R|NotRange3|, notRange4: R|NotRange4|, notRange5: R|NotRange5|, notRange6: R|NotRange6|, notRange7: R|NotRange7|, notRange8: R|NotRange8|, notRange9: R|NotRange9|, range0: R|Range0|, range1: R|Range1|): R|kotlin/Unit| { - lval : R|ERROR CLASS: Unresolved name: iterator| = R|/notRange1|.#() - while(R|/|.#()) { - lval i: R|ERROR CLASS: Unresolved name: next| = R|/|.#() + { + lval : R|ERROR CLASS: Unresolved name: iterator| = R|/notRange1|.#() + while(R|/|.#()) { + lval i: R|ERROR CLASS: Unresolved name: next| = R|/|.#() + } + } - lval : R|kotlin/Unit| = R|/notRange2|.R|/NotRange2.iterator|() - while(R|/|.#()) { - lval i: R|ERROR CLASS: Unresolved name: next| = R|/|.#() + { + lval : R|kotlin/Unit| = R|/notRange2|.R|/NotRange2.iterator|() + while(R|/|.#()) { + lval i: R|ERROR CLASS: Unresolved name: next| = R|/|.#() + } + } - lval : R|ImproperIterator1| = R|/notRange3|.R|/NotRange3.iterator|() - while(R|/|.R|/ImproperIterator1.hasNext|()) { - lval i: R|ERROR CLASS: Unresolved name: next| = R|/|.#() + { + lval : R|ImproperIterator1| = R|/notRange3|.R|/NotRange3.iterator|() + while(R|/|.R|/ImproperIterator1.hasNext|()) { + lval i: R|ERROR CLASS: Unresolved name: next| = R|/|.#() + } + } - lval : R|ImproperIterator2| = R|/notRange4|.R|/NotRange4.iterator|() - while(R|/|.#()) { - lval i: R|kotlin/Boolean| = R|/|.R|/ImproperIterator2.next|() + { + lval : R|ImproperIterator2| = R|/notRange4|.R|/NotRange4.iterator|() + while(R|/|.#()) { + lval i: R|kotlin/Boolean| = R|/|.R|/ImproperIterator2.next|() + } + } - lval : R|ImproperIterator3| = R|/notRange5|.R|/NotRange5.iterator|() - while(R|/|.R|/ImproperIterator3.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator3.next|() + { + lval : R|ImproperIterator3| = R|/notRange5|.R|/NotRange5.iterator|() + while(R|/|.R|/ImproperIterator3.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator3.next|() + } + } - lval : R|AmbiguousHasNextIterator| = R|/notRange6|.R|/NotRange6.iterator|() - while(R|/|.R|/AmbiguousHasNextIterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|/AmbiguousHasNextIterator.next|() + { + lval : R|AmbiguousHasNextIterator| = R|/notRange6|.R|/NotRange6.iterator|() + while(R|/|.R|/AmbiguousHasNextIterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|/AmbiguousHasNextIterator.next|() + } + } - lval : R|ImproperIterator3| = R|/notRange7|.R|/NotRange7.iterator|() - while(R|/|.R|/ImproperIterator3.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator3.next|() + { + lval : R|ImproperIterator3| = R|/notRange7|.R|/NotRange7.iterator|() + while(R|/|.R|/ImproperIterator3.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator3.next|() + } + } - lval : R|ImproperIterator5| = R|/notRange8|.R|/NotRange8.iterator|() - while(R|/|.#()) { - lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator5.next|() + { + lval : R|ImproperIterator5| = R|/notRange8|.R|/NotRange8.iterator|() + while(R|/|.#()) { + lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator5.next|() + } + } - lval : R|ImproperIterator6| = R|/notRange9|.R|/NotRange9.iterator|() - while(R|/|.R|/ImproperIterator6.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator6.next|() + { + lval : R|ImproperIterator6| = R|/notRange9|.R|/NotRange9.iterator|() + while(R|/|.R|/ImproperIterator6.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|/ImproperIterator6.next|() + } + } - lval : R|GoodIterator| = R|/range0|.R|/Range0.iterator|() - while(R|/|.R|/GoodIterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|/GoodIterator.next|() + { + lval : R|GoodIterator| = R|/range0|.R|/Range0.iterator|() + while(R|/|.R|/GoodIterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|/GoodIterator.next|() + } + } - lval : R|kotlin/collections/Iterator| = R|/range1|.R|/Range1.iterator|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval i: R|kotlin/Int| = R|/|.R|SubstitutionOverride|() + { + lval : R|kotlin/collections/Iterator| = R|/range1|.R|/Range1.iterator|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval i: R|kotlin/Int| = R|/|.R|SubstitutionOverride|() + } + } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.fir.txt index ee3e334b5f5..4917ccbdd8d 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/DeepCopyIrTree.fir.txt @@ -42,15 +42,18 @@ FILE: DeepCopyIrTree.kt } ) this@R|/DeepCopyIrTreeWithSymbols|.R|/DeepCopyIrTreeWithSymbols.typeRemapper|.R|/withinScope|(this@R|/DeepCopyIrTreeWithSymbols.copyTypeParametersFrom|, = withinScope@fun (): R|kotlin/Unit| { - lval : R|kotlin/collections/Iterator>| = this@R|/DeepCopyIrTreeWithSymbols.copyTypeParametersFrom|.R|/IrTypeParametersContainer.typeParameters|.R|kotlin/collections/zip|(R|/other|.R|/IrTypeParametersContainer.typeParameters|).R|SubstitutionOverride>|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval : R|kotlin/Pair| = R|/|.R|SubstitutionOverride|>|() - lval thisTypeParameter: R|IrTypeParameter| = R|/|.R|SubstitutionOverride|() - lval otherTypeParameter: R|IrTypeParameter| = R|/|.R|SubstitutionOverride|() - R|/otherTypeParameter|.R|/IrTypeParameter.superTypes|.R|kotlin/collections/mapTo||>(R|/thisTypeParameter|.R|/IrTypeParameter.superTypes|, = mapTo@fun (it: R|IrType|): R|IrType| { - ^ this@R|/DeepCopyIrTreeWithSymbols|.R|/DeepCopyIrTreeWithSymbols.typeRemapper|.R|/TypeRemapper.remapType|(R|/it|) + { + lval : R|kotlin/collections/Iterator>| = this@R|/DeepCopyIrTreeWithSymbols.copyTypeParametersFrom|.R|/IrTypeParametersContainer.typeParameters|.R|kotlin/collections/zip|(R|/other|.R|/IrTypeParametersContainer.typeParameters|).R|SubstitutionOverride>|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval : R|kotlin/Pair| = R|/|.R|SubstitutionOverride|>|() + lval thisTypeParameter: R|IrTypeParameter| = R|/|.R|SubstitutionOverride|() + lval otherTypeParameter: R|IrTypeParameter| = R|/|.R|SubstitutionOverride|() + R|/otherTypeParameter|.R|/IrTypeParameter.superTypes|.R|kotlin/collections/mapTo||>(R|/thisTypeParameter|.R|/IrTypeParameter.superTypes|, = mapTo@fun (it: R|IrType|): R|IrType| { + ^ this@R|/DeepCopyIrTreeWithSymbols|.R|/DeepCopyIrTreeWithSymbols.typeRemapper|.R|/TypeRemapper.remapType|(R|/it|) + } + ) } - ) + } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/valueOfOrNull.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/valueOfOrNull.fir.txt index 29b7586f0f2..ffbf0f06608 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/valueOfOrNull.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/valueOfOrNull.fir.txt @@ -44,13 +44,16 @@ FILE: valueOfOrNull.kt } public final inline fun |> valueOfOrNull(value: R|kotlin/String|): R|E?| { - lval : R|kotlin/collections/Iterator| = R|kotlin/enumValues|().R|SubstitutionOverride|>|() - while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { - lval enumValue: R|E| = R|/|.R|SubstitutionOverride|() - when () { - ==(R|/enumValue|.R|kotlin/Enum.name|, R|/value|) -> { - ^valueOfOrNull R|/enumValue| + { + lval : R|kotlin/collections/Iterator| = R|kotlin/enumValues|().R|SubstitutionOverride|>|() + while(R|/|.R|kotlin/collections/Iterator.hasNext|()) { + lval enumValue: R|E| = R|/|.R|SubstitutionOverride|() + when () { + ==(R|/enumValue|.R|kotlin/Enum.name|, R|/value|) -> { + ^valueOfOrNull R|/enumValue| + } } + } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirForLoopChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirForLoopChecker.kt index cf6a4b1015d..8ff228a26f4 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirForLoopChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirForLoopChecker.kt @@ -38,48 +38,47 @@ import org.jetbrains.kotlin.resolve.calls.tower.isSuccess object FirForLoopChecker : FirBlockChecker() { override fun check(expression: FirBlock, context: CheckerContext, reporter: DiagnosticReporter) { + if (expression.source?.kind != FirFakeSourceElementKind.DesugaredForLoop) return val statements = expression.statements - for ((iteratorDeclaration, whileLoop) in statements.windowed(2)) { - if (iteratorDeclaration !is FirProperty) continue - if (whileLoop !is FirWhileLoop) continue - if (iteratorDeclaration.source?.kind != FirFakeSourceElementKind.DesugaredForLoop) continue - val iteratorCall = iteratorDeclaration.initializer as FirFunctionCall - val source = iteratorCall.explicitReceiver?.source ?: iteratorCall.source - if (checkSpecialFunctionCall( - iteratorCall, - reporter, - source, - context, - ITERATOR_AMBIGUITY, - ITERATOR_MISSING, - unsafeCallFactory = ITERATOR_ON_NULLABLE - ) - ) { - continue - } - val hasNextCall = whileLoop.condition as FirFunctionCall - checkSpecialFunctionCall( - hasNextCall, + val iteratorDeclaration = statements[0] as? FirProperty ?: return + val whileLoop = statements[1] as? FirWhileLoop ?: return + if (iteratorDeclaration.source?.kind != FirFakeSourceElementKind.DesugaredForLoop) return + val iteratorCall = iteratorDeclaration.initializer as FirFunctionCall + val source = iteratorCall.explicitReceiver?.source ?: iteratorCall.source + if (checkSpecialFunctionCall( + iteratorCall, reporter, source, context, - HAS_NEXT_FUNCTION_AMBIGUITY, - HAS_NEXT_MISSING, - noneApplicableFactory = HAS_NEXT_FUNCTION_NONE_APPLICABLE - ) - val elementDeclaration = whileLoop.block.statements.firstOrNull() as? FirProperty ?: continue - if (elementDeclaration.initializer?.source?.kind != FirFakeSourceElementKind.DesugaredForLoop) continue - val nextCall = elementDeclaration.initializer as FirFunctionCall - checkSpecialFunctionCall( - nextCall, - reporter, - source, - context, - NEXT_AMBIGUITY, - NEXT_MISSING, - noneApplicableFactory = NEXT_NONE_APPLICABLE + ITERATOR_AMBIGUITY, + ITERATOR_MISSING, + unsafeCallFactory = ITERATOR_ON_NULLABLE ) + ) { + return } + val hasNextCall = whileLoop.condition as FirFunctionCall + checkSpecialFunctionCall( + hasNextCall, + reporter, + source, + context, + HAS_NEXT_FUNCTION_AMBIGUITY, + HAS_NEXT_MISSING, + noneApplicableFactory = HAS_NEXT_FUNCTION_NONE_APPLICABLE + ) + val elementDeclaration = whileLoop.block.statements.firstOrNull() as? FirProperty ?: return + if (elementDeclaration.initializer?.source?.kind != FirFakeSourceElementKind.DesugaredForLoop) return + val nextCall = elementDeclaration.initializer as FirFunctionCall + checkSpecialFunctionCall( + nextCall, + reporter, + source, + context, + NEXT_AMBIGUITY, + NEXT_MISSING, + noneApplicableFactory = NEXT_NONE_APPLICABLE + ) } private fun checkSpecialFunctionCall( diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index d7153cc0b0c..71c32bb03c0 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -138,7 +138,8 @@ class DeclarationsConverter( return FirBlockBuilder().apply { source = block.toFirSourceElement() firStatements.forEach { firStatement -> - if (firStatement !is FirBlock || firStatement.annotations.isNotEmpty()) { + val isForLoopBlock = firStatement is FirBlock && firStatement.source?.kind == FirFakeSourceElementKind.DesugaredForLoop + if (firStatement !is FirBlock || isForLoopBlock || firStatement.annotations.isNotEmpty()) { statements += firStatement } else { statements += firStatement.statements diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 72db5a2032d..cbc1f366afe 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -193,9 +193,6 @@ open class RawFirBuilder( this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, kind), ) - private fun KtExpression.toFirStatement(errorReason: String): FirStatement = - convertSafe() ?: buildErrorExpression(this.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax)) - private inline fun KtExpression.toFirStatement(errorReasonLazy: () -> String): FirStatement = convertSafe() ?: buildErrorExpression(this.toFirSourceElement(), ConeSimpleDiagnostic(errorReasonLazy(), DiagnosticKind.Syntax)) @@ -1510,7 +1507,8 @@ open class RawFirBuilder( source = expression.toFirSourceElement() for (statement in expression.statements) { val firStatement = statement.toFirStatement { "Statement expected: ${statement.text}" } - if (firStatement !is FirBlock || firStatement.annotations.isNotEmpty()) { + val isForLoopBlock = firStatement is FirBlock && firStatement.source?.kind == FirFakeSourceElementKind.DesugaredForLoop + if (firStatement !is FirBlock || isForLoopBlock || firStatement.annotations.isNotEmpty()) { statements += firStatement } else { statements += firStatement.statements diff --git a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/for.txt b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/for.txt index 1109e2fa975..374dbc613fc 100644 --- a/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/for.txt +++ b/compiler/fir/raw-fir/psi2fir/testData/rawBuilder/expressions/for.txt @@ -1,39 +1,51 @@ FILE: for.kt public? final? fun foo(): R|kotlin/Unit| { - lval : = IntegerLiteral(1).rangeTo#(IntegerLiteral(10)).iterator#() - while(R|/|.hasNext#()) { - lval i: = R|/|.next#() - println#(i#) + { + lval : = IntegerLiteral(1).rangeTo#(IntegerLiteral(10)).iterator#() + while(R|/|.hasNext#()) { + lval i: = R|/|.next#() + println#(i#) + } + } } public? final? fun fooLabeled(): R|kotlin/Unit| { println#(String(!!!)) - lval : = IntegerLiteral(1).rangeTo#(IntegerLiteral(10)).iterator#() - label@while(R|/|.hasNext#()) { - lval i: = R|/|.next#() - when () { - ==(i#, IntegerLiteral(5)) -> { - continue@@@[R|/|.hasNext#()] + { + lval : = IntegerLiteral(1).rangeTo#(IntegerLiteral(10)).iterator#() + label@while(R|/|.hasNext#()) { + lval i: = R|/|.next#() + when () { + ==(i#, IntegerLiteral(5)) -> { + continue@@@[R|/|.hasNext#()] + } } + + println#(i#) } - println#(i#) } println#(String(!!!)) } public? final? fun bar(list: List): R|kotlin/Unit| { - lval : = list#.subList#(IntegerLiteral(0), IntegerLiteral(10)).iterator#() - while(R|/|.hasNext#()) { - lval element: = R|/|.next#() - println#(element#) + { + lval : = list#.subList#(IntegerLiteral(0), IntegerLiteral(10)).iterator#() + while(R|/|.hasNext#()) { + lval element: = R|/|.next#() + println#(element#) + } + } - lval : = list#.subList#(IntegerLiteral(10), IntegerLiteral(20)).iterator#() - while(R|/|.hasNext#()) { - lval element: = R|/|.next#() - println#(element#) + { + lval : = list#.subList#(IntegerLiteral(10), IntegerLiteral(20)).iterator#() + while(R|/|.hasNext#()) { + lval element: = R|/|.next#() + println#(element#) + } + } } @@ -56,20 +68,26 @@ FILE: for.kt } public? final? fun baz(set: Set): R|kotlin/Unit| { - lval : = set#.iterator#() - while(R|/|.hasNext#()) { - lval : = R|/|.next#() - lval x: = R|/|.component1#() - lval y: = R|/|.component2#() - println#((String(x = ), x#.toString#(), String( y = ), y#.toString#())) + { + lval : = set#.iterator#() + while(R|/|.hasNext#()) { + lval : = R|/|.next#() + lval x: = R|/|.component1#() + lval y: = R|/|.component2#() + println#((String(x = ), x#.toString#(), String( y = ), y#.toString#())) + } + } } public? final? fun withParameter(list: List): R|kotlin/Unit| { - lval : = list#.iterator#() - while(R|/|.hasNext#()) { - lval s: Some = R|/|.next#() - println#(s#) + { + lval : = list#.iterator#() + while(R|/|.hasNext#()) { + lval s: Some = R|/|.next#() + println#(s#) + } + } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt index abf4acbac27..24e5759f54b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/illegalConstructionInContractBlock.fir.kt @@ -25,9 +25,9 @@ fun whenInContract(x: Any?, boolean: Boolean) { fun forInContract(x: Any?) { contract { - for (i in 0..1) { + for (i in 0..1) { returns() implies (x is String) - } + } } }