From 85b844c7485c05d98eb63a10f2efa9be33a3e734 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 9 Jun 2021 14:31:16 +0300 Subject: [PATCH] [FIR] Split FirAnonymousObject to expression and declaration --- .../cfg/innerClassInAnonymousObject.dot | 4 +- .../resolve/cfg/localClassesWithImplicit.dot | 406 +++++++++--------- .../bad/callsInPlace/inAnonymousObject.dot | 84 ++-- .../delegates/delegateWithAnonymousObject.dot | 148 +++---- .../declaration/FirSealedSupertypeChecker.kt | 5 +- .../AbstractDiagnosticCollectorVisitor.kt | 4 + .../jetbrains/kotlin/fir/dump/HtmlFirDump.kt | 2 +- .../fir/backend/Fir2IrClassifierStorage.kt | 9 +- .../fir/backend/Fir2IrImplicitCastInserter.kt | 2 +- .../kotlin/fir/backend/Fir2IrVisitor.kt | 10 +- .../converter/DeclarationsConverter.kt | 191 ++++---- .../kotlin/fir/builder/RawFirBuilder.kt | 135 +++--- .../kotlin/fir/resolve/ScopeUtils.kt | 9 +- .../fir/resolve/dfa/FirDataFlowAnalyzer.kt | 4 + .../kotlin/fir/resolve/dfa/cfg/CFGNode.kt | 6 + .../fir/resolve/dfa/cfg/CFGNodeRenderer.kt | 1 + .../dfa/cfg/ControlFlowGraphBuilder.kt | 6 + .../dfa/cfg/ControlFlowGraphNodeBuilder.kt | 3 + .../dfa/cfg/ControlFlowGraphVisitor.kt | 4 + .../transformers/FirSupertypesResolution.kt | 2 +- .../body/resolve/FirBodyResolveTransformer.kt | 7 + .../FirDeclarationsResolveTransformer.kt | 6 - .../FirExpressionsResolveTransformer.kt | 15 + .../fir/declarations/FirAnonymousObject.kt | 6 +- .../kotlin/fir/declarations/FirClass.kt | 38 +- .../declarations/FirClassLikeDeclaration.kt | 21 +- .../fir/declarations/FirRegularClass.kt | 3 +- .../kotlin/fir/declarations/FirTypeAlias.kt | 3 +- .../builder/FirAnonymousObjectBuilder.kt | 6 +- .../impl/FirAnonymousObjectImpl.kt | 7 - .../FirAnonymousObjectExpression.kt | 36 ++ .../kotlin/fir/visitors/FirTransformer.kt | 9 + .../kotlin/fir/visitors/FirVisitor.kt | 3 + .../kotlin/fir/visitors/FirVisitorVoid.kt | 9 + .../org/jetbrains/kotlin/fir/FirRenderer.kt | 4 + .../FirAnonymousObjectExpressionBuilder.kt | 45 ++ .../impl/FirAnonymousObjectExpressionImpl.kt | 51 +++ .../fir/tree/generator/BuilderConfigurator.kt | 1 - .../fir/tree/generator/FirTreeBuilder.kt | 4 +- .../generator/ImplementationConfigurator.kt | 2 +- .../fir/tree/generator/NodeConfigurator.kt | 4 + 41 files changed, 769 insertions(+), 546 deletions(-) create mode 100644 compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirAnonymousObjectExpression.kt create mode 100644 compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt create mode 100644 compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAnonymousObjectExpressionImpl.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot index 813fe0683f2..f810ea9e9a7 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/innerClassInAnonymousObject.dot @@ -46,7 +46,8 @@ digraph innerClassInAnonymousObject_kt { color=red 14 [label="Enter property" style="filled" fillcolor=red]; 15 [label="Exit anonymous object"]; - 16 [label="Exit property" style="filled" fillcolor=red]; + 16 [label="Exit anonymous object expression"]; + 17 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_6 { color=blue @@ -58,6 +59,7 @@ digraph innerClassInAnonymousObject_kt { 15 -> {16}; 15 -> {0 12} [color=green]; 15 -> {0 12} [style=dashed]; + 16 -> {17}; 12 -> {13} [color=green]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot index 104858e4eb9..5c6ab764584 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot @@ -54,20 +54,21 @@ digraph localClassesWithImplicit_kt { } 22 [label="Exit local class test"]; 23 [label="Exit anonymous object"]; - 24 [label="Variable declaration: lval x: R||"]; - 25 [label="Exit block"]; + 24 [label="Exit anonymous object expression"]; + 25 [label="Variable declaration: lval x: R||"]; + 26 [label="Exit block"]; } subgraph cluster_7 { color=blue - 29 [label="Enter class " style="filled" fillcolor=red]; - 30 [label="Exit class " style="filled" fillcolor=red]; + 30 [label="Enter class " style="filled" fillcolor=red]; + 31 [label="Exit class " style="filled" fillcolor=red]; } subgraph cluster_8 { color=blue - 27 [label="Enter class A" style="filled" fillcolor=red]; - 28 [label="Exit class A" style="filled" fillcolor=red]; + 28 [label="Enter class A" style="filled" fillcolor=red]; + 29 [label="Exit class A" style="filled" fillcolor=red]; } - 26 [label="Exit function test" style="filled" fillcolor=red]; + 27 [label="Exit function test" style="filled" fillcolor=red]; } 7 -> {8}; 8 -> {9}; @@ -79,91 +80,92 @@ digraph localClassesWithImplicit_kt { 14 -> {21}; 15 -> {16}; 16 -> {17}; - 17 -> {26}; + 17 -> {27}; 17 -> {18} [style=dotted]; 18 -> {19} [style=dotted]; 19 -> {20} [style=dotted]; 20 -> {21} [style=dotted]; 21 -> {22}; - 21 -> {31 34 69 87} [color=red]; + 21 -> {32 35 70 88} [color=red]; 22 -> {23}; - 22 -> {94 97 132 150} [color=red]; - 22 -> {31 34 69 87 27} [color=green]; - 22 -> {31 34 69 87 27} [style=dashed]; + 22 -> {95 98 133 151} [color=red]; + 22 -> {32 35 70 88 28} [color=green]; + 22 -> {32 35 70 88 28} [style=dashed]; 23 -> {24}; - 23 -> {94 97 132 150 29} [color=green]; - 23 -> {94 97 132 150 29} [style=dashed]; + 23 -> {95 98 133 151 30} [color=green]; + 23 -> {95 98 133 151 30} [style=dashed]; 24 -> {25}; 25 -> {26}; - 27 -> {28} [color=green]; - 29 -> {30} [color=green]; + 26 -> {27}; + 28 -> {29} [color=green]; + 30 -> {31} [color=green]; subgraph cluster_9 { color=red - 31 [label="Enter function " style="filled" fillcolor=red]; - 32 [label="Delegated constructor call: super()"]; - 33 [label="Exit function " style="filled" fillcolor=red]; + 32 [label="Enter function " style="filled" fillcolor=red]; + 33 [label="Delegated constructor call: super()"]; + 34 [label="Exit function " style="filled" fillcolor=red]; } - 31 -> {32}; 32 -> {33}; + 33 -> {34}; subgraph cluster_10 { color=red - 34 [label="Enter function foo" style="filled" fillcolor=red]; + 35 [label="Enter function foo" style="filled" fillcolor=red]; subgraph cluster_11 { color=blue - 35 [label="Enter block"]; - 36 [label="Postponed enter to lambda"]; + 36 [label="Enter block"]; + 37 [label="Postponed enter to lambda"]; subgraph cluster_12 { color=blue - 43 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 44 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; subgraph cluster_13 { color=blue - 44 [label="Enter block"]; - 45 [label="Access variable R|/a|"]; - 46 [label="Access variable R|kotlin/String.length|"]; + 45 [label="Enter block"]; + 46 [label="Access variable R|/a|"]; + 47 [label="Access variable R|kotlin/String.length|"]; subgraph cluster_14 { color=blue - 47 [label="Enter when"]; + 48 [label="Enter when"]; subgraph cluster_15 { color=blue - 48 [label="Enter when branch condition "]; - 49 [label="Access variable R|/b|"]; - 50 [label="Type operator: (R|/b| is R|kotlin/String|)"]; - 51 [label="Exit when branch condition"]; + 49 [label="Enter when branch condition "]; + 50 [label="Access variable R|/b|"]; + 51 [label="Type operator: (R|/b| is R|kotlin/String|)"]; + 52 [label="Exit when branch condition"]; } subgraph cluster_16 { color=blue - 52 [label="Enter when branch condition else"]; - 53 [label="Exit when branch condition"]; + 53 [label="Enter when branch condition else"]; + 54 [label="Exit when branch condition"]; } - 54 [label="Enter when branch result"]; + 55 [label="Enter when branch result"]; subgraph cluster_17 { color=blue - 55 [label="Enter block"]; - 56 [label="Const: Int(1)"]; - 57 [label="Exit block"]; + 56 [label="Enter block"]; + 57 [label="Const: Int(1)"]; + 58 [label="Exit block"]; } - 58 [label="Exit when branch result"]; - 59 [label="Enter when branch result"]; + 59 [label="Exit when branch result"]; + 60 [label="Enter when branch result"]; subgraph cluster_18 { color=blue - 60 [label="Enter block"]; - 61 [label="Access variable R|/b|"]; - 62 [label="Access variable R|kotlin/String.length|"]; - 63 [label="Function call: this@R|/A|.R|/bar|()"]; - 64 [label="Exit block"]; + 61 [label="Enter block"]; + 62 [label="Access variable R|/b|"]; + 63 [label="Access variable R|kotlin/String.length|"]; + 64 [label="Function call: this@R|/A|.R|/bar|()"]; + 65 [label="Exit block"]; } - 65 [label="Exit when branch result"]; - 66 [label="Exit when"]; + 66 [label="Exit when branch result"]; + 67 [label="Exit when"]; } - 67 [label="Exit block"]; + 68 [label="Exit block"]; } - 68 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 69 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } - 37 [label="Postponed exit from lambda"]; - 38 [label="Function call: R|/myRun|(...)"]; - 39 [label="Jump: ^foo R|/myRun|( = myRun@fun (): R|kotlin/Int| { + 38 [label="Postponed exit from lambda"]; + 39 [label="Function call: R|/myRun|(...)"]; + 40 [label="Jump: ^foo R|/myRun|( = myRun@fun (): R|kotlin/Int| { R|/a|.R|kotlin/String.length| ^ when () { (R|/b| is R|kotlin/String|) -> { @@ -177,39 +179,38 @@ digraph localClassesWithImplicit_kt { } )"]; - 40 [label="Stub" style="filled" fillcolor=gray]; - 41 [label="Exit block" style="filled" fillcolor=gray]; + 41 [label="Stub" style="filled" fillcolor=gray]; + 42 [label="Exit block" style="filled" fillcolor=gray]; } - 42 [label="Exit function foo" style="filled" fillcolor=red]; + 43 [label="Exit function foo" style="filled" fillcolor=red]; } - 34 -> {35}; 35 -> {36}; - 36 -> {43}; - 36 -> {37} [color=red]; - 36 -> {43} [style=dashed]; - 37 -> {38}; + 36 -> {37}; + 37 -> {44}; + 37 -> {38} [color=red]; + 37 -> {44} [style=dashed]; 38 -> {39}; - 39 -> {42}; - 39 -> {40} [style=dotted]; + 39 -> {40}; + 40 -> {43}; 40 -> {41} [style=dotted]; 41 -> {42} [style=dotted]; - 43 -> {68 44}; - 44 -> {45}; + 42 -> {43} [style=dotted]; + 44 -> {69 45}; 45 -> {46}; 46 -> {47}; 47 -> {48}; 48 -> {49}; 49 -> {50}; 50 -> {51}; - 51 -> {59 52}; - 52 -> {53}; + 51 -> {52}; + 52 -> {60 53}; 53 -> {54}; 54 -> {55}; 55 -> {56}; 56 -> {57}; 57 -> {58}; - 58 -> {66}; - 59 -> {60}; + 58 -> {59}; + 59 -> {67}; 60 -> {61}; 61 -> {62}; 62 -> {63}; @@ -218,153 +219,154 @@ digraph localClassesWithImplicit_kt { 65 -> {66}; 66 -> {67}; 67 -> {68}; - 68 -> {37} [color=green]; - 68 -> {43} [color=green style=dashed]; + 68 -> {69}; + 69 -> {38} [color=green]; + 69 -> {44} [color=green style=dashed]; subgraph cluster_19 { color=red - 69 [label="Enter function bar" style="filled" fillcolor=red]; + 70 [label="Enter function bar" style="filled" fillcolor=red]; subgraph cluster_20 { color=blue - 70 [label="Enter block"]; - 71 [label="Postponed enter to lambda"]; + 71 [label="Enter block"]; + 72 [label="Postponed enter to lambda"]; subgraph cluster_21 { color=blue - 78 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 79 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; subgraph cluster_22 { color=blue - 79 [label="Enter block"]; - 80 [label="Access variable R|/b|"]; - 81 [label="Access variable #"]; - 82 [label="Access variable R|/a|"]; - 83 [label="Access variable R|kotlin/String.length|"]; - 84 [label="Function call: this@R|/A|.R|/baz|()"]; - 85 [label="Exit block"]; + 80 [label="Enter block"]; + 81 [label="Access variable R|/b|"]; + 82 [label="Access variable #"]; + 83 [label="Access variable R|/a|"]; + 84 [label="Access variable R|kotlin/String.length|"]; + 85 [label="Function call: this@R|/A|.R|/baz|()"]; + 86 [label="Exit block"]; } - 86 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 87 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } - 72 [label="Postponed exit from lambda"]; - 73 [label="Function call: R|/myRun|(...)"]; - 74 [label="Jump: ^bar R|/myRun|( = myRun@fun (): R|kotlin/Int| { + 73 [label="Postponed exit from lambda"]; + 74 [label="Function call: R|/myRun|(...)"]; + 75 [label="Jump: ^bar R|/myRun|( = myRun@fun (): R|kotlin/Int| { R|/b|.# R|/a|.R|kotlin/String.length| ^ this@R|/A|.R|/baz|() } )"]; - 75 [label="Stub" style="filled" fillcolor=gray]; - 76 [label="Exit block" style="filled" fillcolor=gray]; + 76 [label="Stub" style="filled" fillcolor=gray]; + 77 [label="Exit block" style="filled" fillcolor=gray]; } - 77 [label="Exit function bar" style="filled" fillcolor=red]; + 78 [label="Exit function bar" style="filled" fillcolor=red]; } - 69 -> {70}; 70 -> {71}; - 71 -> {78}; - 71 -> {72} [color=red]; - 71 -> {78} [style=dashed]; - 72 -> {73}; + 71 -> {72}; + 72 -> {79}; + 72 -> {73} [color=red]; + 72 -> {79} [style=dashed]; 73 -> {74}; - 74 -> {77}; - 74 -> {75} [style=dotted]; + 74 -> {75}; + 75 -> {78}; 75 -> {76} [style=dotted]; 76 -> {77} [style=dotted]; - 78 -> {86 79}; - 79 -> {80}; + 77 -> {78} [style=dotted]; + 79 -> {87 80}; 80 -> {81}; 81 -> {82}; 82 -> {83}; 83 -> {84}; 84 -> {85}; 85 -> {86}; - 86 -> {72} [color=green]; - 86 -> {78} [color=green style=dashed]; + 86 -> {87}; + 87 -> {73} [color=green]; + 87 -> {79} [color=green style=dashed]; subgraph cluster_23 { color=red - 87 [label="Enter function baz" style="filled" fillcolor=red]; + 88 [label="Enter function baz" style="filled" fillcolor=red]; subgraph cluster_24 { color=blue - 88 [label="Enter block"]; - 89 [label="Const: Int(1)"]; - 90 [label="Jump: ^baz Int(1)"]; - 91 [label="Stub" style="filled" fillcolor=gray]; - 92 [label="Exit block" style="filled" fillcolor=gray]; + 89 [label="Enter block"]; + 90 [label="Const: Int(1)"]; + 91 [label="Jump: ^baz Int(1)"]; + 92 [label="Stub" style="filled" fillcolor=gray]; + 93 [label="Exit block" style="filled" fillcolor=gray]; } - 93 [label="Exit function baz" style="filled" fillcolor=red]; + 94 [label="Exit function baz" style="filled" fillcolor=red]; } - 87 -> {88}; 88 -> {89}; 89 -> {90}; - 90 -> {93}; - 90 -> {91} [style=dotted]; + 90 -> {91}; + 91 -> {94}; 91 -> {92} [style=dotted]; 92 -> {93} [style=dotted]; + 93 -> {94} [style=dotted]; subgraph cluster_25 { color=red - 94 [label="Enter function " style="filled" fillcolor=red]; - 95 [label="Delegated constructor call: super()"]; - 96 [label="Exit function " style="filled" fillcolor=red]; + 95 [label="Enter function " style="filled" fillcolor=red]; + 96 [label="Delegated constructor call: super()"]; + 97 [label="Exit function " style="filled" fillcolor=red]; } - 94 -> {95}; 95 -> {96}; + 96 -> {97}; subgraph cluster_26 { color=red - 97 [label="Enter function foo" style="filled" fillcolor=red]; + 98 [label="Enter function foo" style="filled" fillcolor=red]; subgraph cluster_27 { color=blue - 98 [label="Enter block"]; - 99 [label="Postponed enter to lambda"]; + 99 [label="Enter block"]; + 100 [label="Postponed enter to lambda"]; subgraph cluster_28 { color=blue - 106 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 107 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; subgraph cluster_29 { color=blue - 107 [label="Enter block"]; - 108 [label="Access variable R|/a|"]; - 109 [label="Access variable R|kotlin/String.length|"]; + 108 [label="Enter block"]; + 109 [label="Access variable R|/a|"]; + 110 [label="Access variable R|kotlin/String.length|"]; subgraph cluster_30 { color=blue - 110 [label="Enter when"]; + 111 [label="Enter when"]; subgraph cluster_31 { color=blue - 111 [label="Enter when branch condition "]; - 112 [label="Access variable R|/b|"]; - 113 [label="Type operator: (R|/b| is R|kotlin/String|)"]; - 114 [label="Exit when branch condition"]; + 112 [label="Enter when branch condition "]; + 113 [label="Access variable R|/b|"]; + 114 [label="Type operator: (R|/b| is R|kotlin/String|)"]; + 115 [label="Exit when branch condition"]; } subgraph cluster_32 { color=blue - 115 [label="Enter when branch condition else"]; - 116 [label="Exit when branch condition"]; + 116 [label="Enter when branch condition else"]; + 117 [label="Exit when branch condition"]; } - 117 [label="Enter when branch result"]; + 118 [label="Enter when branch result"]; subgraph cluster_33 { color=blue - 118 [label="Enter block"]; - 119 [label="Const: Int(1)"]; - 120 [label="Exit block"]; + 119 [label="Enter block"]; + 120 [label="Const: Int(1)"]; + 121 [label="Exit block"]; } - 121 [label="Exit when branch result"]; - 122 [label="Enter when branch result"]; + 122 [label="Exit when branch result"]; + 123 [label="Enter when branch result"]; subgraph cluster_34 { color=blue - 123 [label="Enter block"]; - 124 [label="Access variable R|/b|"]; - 125 [label="Access variable R|kotlin/String.length|"]; - 126 [label="Function call: this@R|/|.R|/.bar|()"]; - 127 [label="Exit block"]; + 124 [label="Enter block"]; + 125 [label="Access variable R|/b|"]; + 126 [label="Access variable R|kotlin/String.length|"]; + 127 [label="Function call: this@R|/|.R|/.bar|()"]; + 128 [label="Exit block"]; } - 128 [label="Exit when branch result"]; - 129 [label="Exit when"]; + 129 [label="Exit when branch result"]; + 130 [label="Exit when"]; } - 130 [label="Exit block"]; + 131 [label="Exit block"]; } - 131 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 132 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } - 100 [label="Postponed exit from lambda"]; - 101 [label="Function call: R|/myRun|(...)"]; - 102 [label="Jump: ^foo R|/myRun|( = myRun@fun (): R|kotlin/Int| { + 101 [label="Postponed exit from lambda"]; + 102 [label="Function call: R|/myRun|(...)"]; + 103 [label="Jump: ^foo R|/myRun|( = myRun@fun (): R|kotlin/Int| { R|/a|.R|kotlin/String.length| ^ when () { (R|/b| is R|kotlin/String|) -> { @@ -378,39 +380,38 @@ digraph localClassesWithImplicit_kt { } )"]; - 103 [label="Stub" style="filled" fillcolor=gray]; - 104 [label="Exit block" style="filled" fillcolor=gray]; + 104 [label="Stub" style="filled" fillcolor=gray]; + 105 [label="Exit block" style="filled" fillcolor=gray]; } - 105 [label="Exit function foo" style="filled" fillcolor=red]; + 106 [label="Exit function foo" style="filled" fillcolor=red]; } - 97 -> {98}; 98 -> {99}; - 99 -> {106}; - 99 -> {100} [color=red]; - 99 -> {106} [style=dashed]; - 100 -> {101}; + 99 -> {100}; + 100 -> {107}; + 100 -> {101} [color=red]; + 100 -> {107} [style=dashed]; 101 -> {102}; - 102 -> {105}; - 102 -> {103} [style=dotted]; + 102 -> {103}; + 103 -> {106}; 103 -> {104} [style=dotted]; 104 -> {105} [style=dotted]; - 106 -> {131 107}; - 107 -> {108}; + 105 -> {106} [style=dotted]; + 107 -> {132 108}; 108 -> {109}; 109 -> {110}; 110 -> {111}; 111 -> {112}; 112 -> {113}; 113 -> {114}; - 114 -> {122 115}; - 115 -> {116}; + 114 -> {115}; + 115 -> {123 116}; 116 -> {117}; 117 -> {118}; 118 -> {119}; 119 -> {120}; 120 -> {121}; - 121 -> {129}; - 122 -> {123}; + 121 -> {122}; + 122 -> {130}; 123 -> {124}; 124 -> {125}; 125 -> {126}; @@ -419,85 +420,86 @@ digraph localClassesWithImplicit_kt { 128 -> {129}; 129 -> {130}; 130 -> {131}; - 131 -> {100} [color=green]; - 131 -> {106} [color=green style=dashed]; + 131 -> {132}; + 132 -> {101} [color=green]; + 132 -> {107} [color=green style=dashed]; subgraph cluster_35 { color=red - 132 [label="Enter function bar" style="filled" fillcolor=red]; + 133 [label="Enter function bar" style="filled" fillcolor=red]; subgraph cluster_36 { color=blue - 133 [label="Enter block"]; - 134 [label="Postponed enter to lambda"]; + 134 [label="Enter block"]; + 135 [label="Postponed enter to lambda"]; subgraph cluster_37 { color=blue - 141 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 142 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; subgraph cluster_38 { color=blue - 142 [label="Enter block"]; - 143 [label="Access variable R|/a|"]; - 144 [label="Access variable R|kotlin/String.length|"]; - 145 [label="Access variable R|/b|"]; - 146 [label="Access variable #"]; - 147 [label="Function call: this@R|/|.R|/.baz|()"]; - 148 [label="Exit block"]; + 143 [label="Enter block"]; + 144 [label="Access variable R|/a|"]; + 145 [label="Access variable R|kotlin/String.length|"]; + 146 [label="Access variable R|/b|"]; + 147 [label="Access variable #"]; + 148 [label="Function call: this@R|/|.R|/.baz|()"]; + 149 [label="Exit block"]; } - 149 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 150 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } - 135 [label="Postponed exit from lambda"]; - 136 [label="Function call: R|/myRun|(...)"]; - 137 [label="Jump: ^bar R|/myRun|( = myRun@fun (): R|kotlin/Int| { + 136 [label="Postponed exit from lambda"]; + 137 [label="Function call: R|/myRun|(...)"]; + 138 [label="Jump: ^bar R|/myRun|( = myRun@fun (): R|kotlin/Int| { R|/a|.R|kotlin/String.length| R|/b|.# ^ this@R|/|.R|/.baz|() } )"]; - 138 [label="Stub" style="filled" fillcolor=gray]; - 139 [label="Exit block" style="filled" fillcolor=gray]; + 139 [label="Stub" style="filled" fillcolor=gray]; + 140 [label="Exit block" style="filled" fillcolor=gray]; } - 140 [label="Exit function bar" style="filled" fillcolor=red]; + 141 [label="Exit function bar" style="filled" fillcolor=red]; } - 132 -> {133}; 133 -> {134}; - 134 -> {141}; - 134 -> {135} [color=red]; - 134 -> {141} [style=dashed]; - 135 -> {136}; + 134 -> {135}; + 135 -> {142}; + 135 -> {136} [color=red]; + 135 -> {142} [style=dashed]; 136 -> {137}; - 137 -> {140}; - 137 -> {138} [style=dotted]; + 137 -> {138}; + 138 -> {141}; 138 -> {139} [style=dotted]; 139 -> {140} [style=dotted]; - 141 -> {149 142}; - 142 -> {143}; + 140 -> {141} [style=dotted]; + 142 -> {150 143}; 143 -> {144}; 144 -> {145}; 145 -> {146}; 146 -> {147}; 147 -> {148}; 148 -> {149}; - 149 -> {135} [color=green]; - 149 -> {141} [color=green style=dashed]; + 149 -> {150}; + 150 -> {136} [color=green]; + 150 -> {142} [color=green style=dashed]; subgraph cluster_39 { color=red - 150 [label="Enter function baz" style="filled" fillcolor=red]; + 151 [label="Enter function baz" style="filled" fillcolor=red]; subgraph cluster_40 { color=blue - 151 [label="Enter block"]; - 152 [label="Const: Int(1)"]; - 153 [label="Jump: ^baz Int(1)"]; - 154 [label="Stub" style="filled" fillcolor=gray]; - 155 [label="Exit block" style="filled" fillcolor=gray]; + 152 [label="Enter block"]; + 153 [label="Const: Int(1)"]; + 154 [label="Jump: ^baz Int(1)"]; + 155 [label="Stub" style="filled" fillcolor=gray]; + 156 [label="Exit block" style="filled" fillcolor=gray]; } - 156 [label="Exit function baz" style="filled" fillcolor=red]; + 157 [label="Exit function baz" style="filled" fillcolor=red]; } - 150 -> {151}; 151 -> {152}; 152 -> {153}; - 153 -> {156}; - 153 -> {154} [style=dotted]; + 153 -> {154}; + 154 -> {157}; 154 -> {155} [style=dotted]; 155 -> {156} [style=dotted]; + 156 -> {157} [style=dotted]; } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot index 2fcac12ad47..c9d15882863 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot @@ -10,92 +10,94 @@ digraph inAnonymousObject_kt { color=blue 1 [label="Enter block"]; 2 [label="Exit anonymous object"]; - 3 [label="Variable declaration: lval obj: R||"]; - 4 [label="Access variable R|/obj|"]; - 5 [label="Function call: R|/obj|.R|/.run|()"]; - 6 [label="Function call: R|/d|.R|SubstitutionOverride|()"]; - 7 [label="Exit block"]; + 3 [label="Exit anonymous object expression"]; + 4 [label="Variable declaration: lval obj: R||"]; + 5 [label="Access variable R|/obj|"]; + 6 [label="Function call: R|/obj|.R|/.run|()"]; + 7 [label="Function call: R|/d|.R|SubstitutionOverride|()"]; + 8 [label="Exit block"]; } - 8 [label="Exit function foo" style="filled" fillcolor=red]; + 9 [label="Exit function foo" style="filled" fillcolor=red]; } subgraph cluster_2 { color=blue - 9 [label="Enter class " style="filled" fillcolor=red]; - 10 [label="Part of class initialization"]; + 10 [label="Enter class " style="filled" fillcolor=red]; 11 [label="Part of class initialization"]; - 12 [label="Exit class " style="filled" fillcolor=red]; + 12 [label="Part of class initialization"]; + 13 [label="Exit class " style="filled" fillcolor=red]; } 0 -> {1}; 1 -> {2}; - 1 -> {13 16 19 25} [color=red]; + 1 -> {14 17 20 26} [color=red]; 2 -> {3}; - 2 -> {13 25 9} [color=green]; - 2 -> {13 25 9} [style=dashed]; + 2 -> {14 26 10} [color=green]; + 2 -> {14 26 10} [style=dashed]; 3 -> {4}; 4 -> {5}; 5 -> {6}; 6 -> {7}; 7 -> {8}; - 9 -> {10} [color=green]; - 10 -> {11} [style=dotted]; - 10 -> {16} [color=green]; - 10 -> {16} [style=dashed]; + 8 -> {9}; + 10 -> {11} [color=green]; 11 -> {12} [style=dotted]; - 11 -> {19} [color=green]; - 11 -> {19} [style=dashed]; + 11 -> {17} [color=green]; + 11 -> {17} [style=dashed]; + 12 -> {13} [style=dotted]; + 12 -> {20} [color=green]; + 12 -> {20} [style=dashed]; subgraph cluster_3 { color=red - 13 [label="Enter function " style="filled" fillcolor=red]; - 14 [label="Delegated constructor call: super()"]; - 15 [label="Exit function " style="filled" fillcolor=red]; + 14 [label="Enter function " style="filled" fillcolor=red]; + 15 [label="Delegated constructor call: super()"]; + 16 [label="Exit function " style="filled" fillcolor=red]; } - 13 -> {14}; 14 -> {15}; + 15 -> {16}; subgraph cluster_4 { color=red - 16 [label="Enter property" style="filled" fillcolor=red]; - 17 [label="Access variable R|/a|"]; - 18 [label="Exit property" style="filled" fillcolor=red]; + 17 [label="Enter property" style="filled" fillcolor=red]; + 18 [label="Access variable R|/a|"]; + 19 [label="Exit property" style="filled" fillcolor=red]; } - 16 -> {17}; 17 -> {18}; - 18 -> {11} [color=green]; + 18 -> {19}; + 19 -> {12} [color=green]; subgraph cluster_5 { color=red - 19 [label="Enter init block" style="filled" fillcolor=red]; + 20 [label="Enter init block" style="filled" fillcolor=red]; subgraph cluster_6 { color=blue - 20 [label="Enter block"]; - 21 [label="Access variable R|/b|"]; - 22 [label="Assignment: R|/.leaked|"]; - 23 [label="Exit block"]; + 21 [label="Enter block"]; + 22 [label="Access variable R|/b|"]; + 23 [label="Assignment: R|/.leaked|"]; + 24 [label="Exit block"]; } - 24 [label="Exit init block" style="filled" fillcolor=red]; + 25 [label="Exit init block" style="filled" fillcolor=red]; } - 19 -> {20}; 20 -> {21}; 21 -> {22}; 22 -> {23}; 23 -> {24}; - 24 -> {12} [color=green]; + 24 -> {25}; + 25 -> {13} [color=green]; subgraph cluster_7 { color=red - 25 [label="Enter function run" style="filled" fillcolor=red]; + 26 [label="Enter function run" style="filled" fillcolor=red]; subgraph cluster_8 { color=blue - 26 [label="Enter block"]; - 27 [label="Function call: R|/c|.R|SubstitutionOverride|()"]; - 28 [label="Exit block"]; + 27 [label="Enter block"]; + 28 [label="Function call: R|/c|.R|SubstitutionOverride|()"]; + 29 [label="Exit block"]; } - 29 [label="Exit function run" style="filled" fillcolor=red]; + 30 [label="Exit function run" style="filled" fillcolor=red]; } - 25 -> {26}; 26 -> {27}; 27 -> {28}; 28 -> {29}; + 29 -> {30}; } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot index 84f6eb6028c..bcd1ab93002 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot @@ -80,8 +80,8 @@ digraph delegateWithAnonymousObject_kt { } 22 -> {23} [color=green]; 23 -> {24} [style=dotted]; - 23 -> {71} [color=green]; - 23 -> {71} [style=dashed]; + 23 -> {72} [color=green]; + 23 -> {72} [style=dashed]; subgraph cluster_9 { color=red @@ -94,115 +94,115 @@ digraph delegateWithAnonymousObject_kt { subgraph cluster_10 { color=red - 35 [label="Enter function " style="filled" fillcolor=red]; - 36 [label="Delegated constructor call: super()"]; - 37 [label="Exit function " style="filled" fillcolor=red]; + 36 [label="Enter function " style="filled" fillcolor=red]; + 37 [label="Delegated constructor call: super()"]; + 38 [label="Exit function " style="filled" fillcolor=red]; } - 35 -> {36}; 36 -> {37}; + 37 -> {38}; subgraph cluster_11 { color=red - 38 [label="Enter function getValue" style="filled" fillcolor=red]; + 39 [label="Enter function getValue" style="filled" fillcolor=red]; subgraph cluster_12 { color=blue - 39 [label="Enter block"]; - 40 [label="Function call: R|/IssueListView.IssueListView|()"]; - 41 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"]; - 42 [label="Stub" style="filled" fillcolor=gray]; - 43 [label="Exit block" style="filled" fillcolor=gray]; + 40 [label="Enter block"]; + 41 [label="Function call: R|/IssueListView.IssueListView|()"]; + 42 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"]; + 43 [label="Stub" style="filled" fillcolor=gray]; + 44 [label="Exit block" style="filled" fillcolor=gray]; } - 44 [label="Exit function getValue" style="filled" fillcolor=red]; + 45 [label="Exit function getValue" style="filled" fillcolor=red]; } - 38 -> {39}; 39 -> {40}; 40 -> {41}; - 41 -> {44}; - 41 -> {42} [style=dotted]; + 41 -> {42}; + 42 -> {45}; 42 -> {43} [style=dotted]; 43 -> {44} [style=dotted]; + 44 -> {45} [style=dotted]; subgraph cluster_13 { color=red - 45 [label="Enter function setValue" style="filled" fillcolor=red]; + 46 [label="Enter function setValue" style="filled" fillcolor=red]; subgraph cluster_14 { color=blue - 46 [label="Enter block"]; - 47 [label="Function call: R|/IssueListView.IssueListView|()"]; - 48 [label="Access variable R|/value|"]; - 49 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)"]; - 50 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|/value|)"]; - 51 [label="Stub" style="filled" fillcolor=gray]; - 52 [label="Exit block" style="filled" fillcolor=gray]; + 47 [label="Enter block"]; + 48 [label="Function call: R|/IssueListView.IssueListView|()"]; + 49 [label="Access variable R|/value|"]; + 50 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)"]; + 51 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|/value|)"]; + 52 [label="Stub" style="filled" fillcolor=gray]; + 53 [label="Exit block" style="filled" fillcolor=gray]; } - 53 [label="Exit function setValue" style="filled" fillcolor=red]; + 54 [label="Exit function setValue" style="filled" fillcolor=red]; } - 45 -> {46}; 46 -> {47}; 47 -> {48}; 48 -> {49}; 49 -> {50}; - 50 -> {53}; - 50 -> {51} [style=dotted]; + 50 -> {51}; + 51 -> {54}; 51 -> {52} [style=dotted]; 52 -> {53} [style=dotted]; + 53 -> {54} [style=dotted]; subgraph cluster_15 { color=red - 54 [label="Enter function getter" style="filled" fillcolor=red]; + 55 [label="Enter function getter" style="filled" fillcolor=red]; subgraph cluster_16 { color=blue - 55 [label="Enter block"]; - 56 [label="Access variable D|/IssuesListUserProfile.issueListView|"]; - 57 [label="Access variable this@R|/IssuesListUserProfile|"]; - 58 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride|(...)"]; - 59 [label="Jump: ^ this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride|(this@R|/IssuesListUserProfile|, ::R|/IssuesListUserProfile.issueListView|)"]; - 60 [label="Stub" style="filled" fillcolor=gray]; - 61 [label="Exit block" style="filled" fillcolor=gray]; + 56 [label="Enter block"]; + 57 [label="Access variable D|/IssuesListUserProfile.issueListView|"]; + 58 [label="Access variable this@R|/IssuesListUserProfile|"]; + 59 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride|(...)"]; + 60 [label="Jump: ^ this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride|(this@R|/IssuesListUserProfile|, ::R|/IssuesListUserProfile.issueListView|)"]; + 61 [label="Stub" style="filled" fillcolor=gray]; + 62 [label="Exit block" style="filled" fillcolor=gray]; } - 62 [label="Exit function getter" style="filled" fillcolor=red]; + 63 [label="Exit function getter" style="filled" fillcolor=red]; } - 54 -> {55}; 55 -> {56}; 56 -> {57}; 57 -> {58}; 58 -> {59}; - 59 -> {62}; - 59 -> {60} [style=dotted]; + 59 -> {60}; + 60 -> {63}; 60 -> {61} [style=dotted]; 61 -> {62} [style=dotted]; + 62 -> {63} [style=dotted]; subgraph cluster_17 { color=red - 63 [label="Enter function setter" style="filled" fillcolor=red]; + 64 [label="Enter function setter" style="filled" fillcolor=red]; subgraph cluster_18 { color=blue - 64 [label="Enter block"]; - 65 [label="Access variable D|/IssuesListUserProfile.issueListView|"]; - 66 [label="Access variable this@R|/IssuesListUserProfile|"]; - 67 [label="Access variable R|/issueListView|"]; - 68 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride|(...)"]; - 69 [label="Exit block"]; + 65 [label="Enter block"]; + 66 [label="Access variable D|/IssuesListUserProfile.issueListView|"]; + 67 [label="Access variable this@R|/IssuesListUserProfile|"]; + 68 [label="Access variable R|/issueListView|"]; + 69 [label="Function call: this@R|/IssuesListUserProfile|.D|/IssuesListUserProfile.issueListView|.R|SubstitutionOverride|(...)"]; + 70 [label="Exit block"]; } - 70 [label="Exit function setter" style="filled" fillcolor=red]; + 71 [label="Exit function setter" style="filled" fillcolor=red]; } - 63 -> {64}; 64 -> {65}; 65 -> {66}; 66 -> {67}; 67 -> {68}; 68 -> {69}; 69 -> {70}; + 70 -> {71}; subgraph cluster_19 { color=red - 71 [label="Enter property" style="filled" fillcolor=red]; - 72 [label="Postponed enter to lambda"]; - 73 [label="Postponed exit from lambda"]; - 74 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...)"]; - 75 [label="Access variable this@R|/IssuesListUserProfile|"]; - 76 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...).#(...)"]; - 77 [label="Postponed enter to lambda"]; + 72 [label="Enter property" style="filled" fillcolor=red]; + 73 [label="Postponed enter to lambda"]; + 74 [label="Postponed exit from lambda"]; + 75 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...)"]; + 76 [label="Access variable this@R|/IssuesListUserProfile|"]; + 77 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...).#(...)"]; + 78 [label="Postponed enter to lambda"]; subgraph cluster_20 { color=blue 28 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; @@ -210,38 +210,40 @@ digraph delegateWithAnonymousObject_kt { color=blue 29 [label="Enter block"]; 30 [label="Exit anonymous object"]; - 31 [label="Exit block"]; + 31 [label="Exit anonymous object expression"]; + 32 [label="Exit block"]; } - 32 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + 33 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; } subgraph cluster_22 { color=blue - 33 [label="Enter class " style="filled" fillcolor=red]; - 34 [label="Exit class " style="filled" fillcolor=red]; + 34 [label="Enter class " style="filled" fillcolor=red]; + 35 [label="Exit class " style="filled" fillcolor=red]; } - 78 [label="Postponed exit from lambda"]; - 79 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...)"]; - 80 [label="Exit property" style="filled" fillcolor=red]; + 79 [label="Postponed exit from lambda"]; + 80 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...)"]; + 81 [label="Exit property" style="filled" fillcolor=red]; } - 71 -> {72}; 72 -> {73}; - 72 -> {} [style=dashed]; 73 -> {74}; + 73 -> {} [style=dashed]; 74 -> {75}; 75 -> {76}; 76 -> {77}; - 77 -> {78 28}; - 77 -> {28} [style=dashed]; - 78 -> {79}; + 77 -> {78}; + 78 -> {79 28}; + 78 -> {28} [style=dashed]; 79 -> {80}; - 80 -> {24} [color=green]; + 80 -> {81}; + 81 -> {24} [color=green]; 28 -> {29}; 29 -> {30}; - 29 -> {35 38 45} [color=red]; + 29 -> {36 39 46} [color=red]; 30 -> {31}; - 30 -> {35 38 45 33} [color=green]; - 30 -> {35 38 45 33} [style=dashed]; + 30 -> {36 39 46 34} [color=green]; + 30 -> {36 39 46 34} [style=dashed]; 31 -> {32}; - 33 -> {34} [color=green]; + 32 -> {33}; + 34 -> {35} [color=green]; } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt index 35f1d502457..2c6716a3c4f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSealedSupertypeChecker.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression import org.jetbrains.kotlin.fir.resolve.symbolProvider import org.jetbrains.kotlin.fir.types.classId import org.jetbrains.kotlin.fir.types.coneType @@ -26,8 +27,8 @@ object FirSealedSupertypeChecker : FirMemberDeclarationChecker() { checkGlobalDeclaration(declaration, context, reporter) } } else if (declaration is FirProperty) { - val initializer = declaration.initializer.safeAs>() ?: return - checkLocalDeclaration(initializer, context, reporter) + val initializer = declaration.initializer as? FirAnonymousObjectExpression ?: return + checkLocalDeclaration(initializer.anonymousObject, context, reporter) } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt index 3fa25efa178..c4c2fa5eb5b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollectorVisitor.kt @@ -77,6 +77,10 @@ abstract class AbstractDiagnosticCollectorVisitor( } } + override fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression, data: Nothing?) { + anonymousObjectExpression.anonymousObject.accept(this, data) + } + override fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: Nothing?) { withSuppressedDiagnostics(anonymousObject) { visitClassAndChildren(anonymousObject, anonymousObject.defaultType()) diff --git a/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt b/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt index 79c5b8edbc2..0bd189f64ca 100644 --- a/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt +++ b/compiler/fir/dump/src/org/jetbrains/kotlin/fir/dump/HtmlFirDump.kt @@ -1512,7 +1512,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver is FirGetClassCall -> generate(expression) is FirContinueExpression -> generate(expression) is FirBreakExpression -> generate(expression) - is FirAnonymousObject -> generate(expression) + is FirAnonymousObjectExpression -> generate(expression.anonymousObject) is FirUnitExpression -> generate(expression) is FirStringConcatenationCall -> generate(expression) is FirAnonymousFunction -> generate(expression, isStatement = false) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt index cff7406a52b..b868c8ae85c 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyClass import org.jetbrains.kotlin.fir.resolve.firProvider import org.jetbrains.kotlin.fir.resolve.symbolProvider @@ -368,7 +369,7 @@ class Fir2IrClassifierStorage( } fun putEnumEntryClassInScope(enumEntry: FirEnumEntry, correspondingClass: IrClass) { - localStorage.putLocalClass(enumEntry.initializer as FirAnonymousObject, correspondingClass) + localStorage.putLocalClass((enumEntry.initializer as FirAnonymousObjectExpression).anonymousObject, correspondingClass) } internal fun getCachedIrEnumEntry(enumEntry: FirEnumEntry): IrEnumEntry? = enumEntryCache[enumEntry] @@ -396,10 +397,10 @@ class Fir2IrClassifierStorage( this.parent = irParent } val initializer = enumEntry.initializer - if (initializer is FirAnonymousObject) { + if (initializer is FirAnonymousObjectExpression) { // An enum entry with its own members - if (initializer.declarations.any { it !is FirConstructor }) { - val klass = getIrAnonymousObjectForEnumEntry(initializer, enumEntry.name, irParent) + if (initializer.anonymousObject.declarations.any { it !is FirConstructor }) { + val klass = getIrAnonymousObjectForEnumEntry(initializer.anonymousObject, enumEntry.name, irParent) this.correspondingClass = klass } // Otherwise, this is a default-ish enum entry whose initializer would be a delegating constructor call, diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt index b1bb1771946..60e48c70f59 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt @@ -44,7 +44,7 @@ class Fir2IrImplicitCastInserter( override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: IrElement): IrElement = data - override fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: IrElement): IrElement = data + override fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression, data: IrElement): IrElement = data override fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction, data: IrElement): IrElement = data diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index ea09fc078b2..5be246f64eb 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -106,7 +106,7 @@ class Fir2IrVisitor( if (correspondingClass != null) { declarationStorage.enterScope(irEnumEntry) classifierStorage.putEnumEntryClassInScope(enumEntry, correspondingClass) - val anonymousObject = enumEntry.initializer as FirAnonymousObject + val anonymousObject = (enumEntry.initializer as FirAnonymousObjectExpression).anonymousObject converter.processAnonymousObjectMembers(anonymousObject, correspondingClass) conversionScope.withParent(correspondingClass) { conversionScope.withContainingFirClass(anonymousObject) { @@ -123,10 +123,10 @@ class Fir2IrVisitor( ) } declarationStorage.leaveScope(irEnumEntry) - } else if (initializer is FirAnonymousObject) { + } else if (initializer is FirAnonymousObjectExpression) { // Otherwise, this is a default-ish enum entry, which doesn't need its own synthetic class. // During raw FIR building, we put the delegated constructor call inside an anonymous object. - val delegatedConstructor = initializer.primaryConstructor?.delegatedConstructor + val delegatedConstructor = initializer.anonymousObject.primaryConstructor?.delegatedConstructor if (delegatedConstructor != null) { with(memberGenerator) { irEnumEntry.initializerExpression = irFactory.createExpressionBody( @@ -159,6 +159,10 @@ class Fir2IrVisitor( } } + override fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression, data: Any?): IrElement { + return visitAnonymousObject(anonymousObjectExpression.anonymousObject, data) + } + override fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: Any?): IrElement { val irParent = conversionScope.parentFromStack() // NB: for implicit types it is possible that anonymous object is already cached 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 3f6a2923f33..4eebc9eba08 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 @@ -546,72 +546,75 @@ class DeclarationsConverter( */ fun convertObjectLiteral(objectLiteral: LighterASTNode): FirElement { return withChildClassName(ANONYMOUS_OBJECT_NAME) { - buildAnonymousObject { + buildAnonymousObjectExpression { val objectDeclaration = objectLiteral.getChildNodesByType(OBJECT_DECLARATION).first() - source = objectDeclaration.toFirSourceElement() - origin = FirDeclarationOrigin.Source - moduleData = baseModuleData - classKind = ClassKind.OBJECT - scopeProvider = baseScopeProvider - symbol = FirAnonymousObjectSymbol() - context.applyToActualCapturedTypeParameters(false) { - typeParameters += buildOuterClassTypeParameterRef { this.symbol = it } - } - val delegatedSelfType = objectLiteral.toDelegatedSelfType(this) - registerSelfType(delegatedSelfType) + val sourceElement = objectDeclaration.toFirSourceElement() + source = sourceElement + anonymousObject = buildAnonymousObject { + source = objectDeclaration.toFirSourceElement() + origin = FirDeclarationOrigin.Source + moduleData = baseModuleData + classKind = ClassKind.OBJECT + scopeProvider = baseScopeProvider + symbol = FirAnonymousObjectSymbol() + context.applyToActualCapturedTypeParameters(false) { + typeParameters += buildOuterClassTypeParameterRef { this.symbol = it } } + val delegatedSelfType = objectLiteral.toDelegatedSelfType(this) + registerSelfType(delegatedSelfType) - var modifiers = Modifier() - var primaryConstructor: LighterASTNode? = null - val superTypeRefs = mutableListOf() - val superTypeCallEntry = mutableListOf() - var delegatedSuperTypeRef: FirTypeRef? = null - var classBody: LighterASTNode? = null - var delegatedConstructorSource: FirLightSourceElement? = null - var delegateFields: List? = null + var modifiers = Modifier() + var primaryConstructor: LighterASTNode? = null + val superTypeRefs = mutableListOf() + val superTypeCallEntry = mutableListOf() + var delegatedSuperTypeRef: FirTypeRef? = null + var classBody: LighterASTNode? = null + var delegatedConstructorSource: FirLightSourceElement? = null + var delegateFields: List? = null - objectDeclaration.forEachChildren { - when (it.tokenType) { - MODIFIER_LIST -> modifiers = convertModifierList(it) - PRIMARY_CONSTRUCTOR -> primaryConstructor = it - SUPER_TYPE_LIST -> convertDelegationSpecifiers(it).let { specifiers -> - delegatedSuperTypeRef = specifiers.delegatedSuperTypeRef - superTypeRefs += specifiers.superTypesRef - superTypeCallEntry += specifiers.delegatedConstructorArguments - delegatedConstructorSource = specifiers.delegatedConstructorSource - delegateFields = specifiers.delegateFields + objectDeclaration.forEachChildren { + when (it.tokenType) { + MODIFIER_LIST -> modifiers = convertModifierList(it) + PRIMARY_CONSTRUCTOR -> primaryConstructor = it + SUPER_TYPE_LIST -> convertDelegationSpecifiers(it).let { specifiers -> + delegatedSuperTypeRef = specifiers.delegatedSuperTypeRef + superTypeRefs += specifiers.superTypesRef + superTypeCallEntry += specifiers.delegatedConstructorArguments + delegatedConstructorSource = specifiers.delegatedConstructorSource + delegateFields = specifiers.delegateFields + } + CLASS_BODY -> classBody = it } - CLASS_BODY -> classBody = it } - } - superTypeRefs.ifEmpty { - superTypeRefs += implicitAnyType - delegatedSuperTypeRef = implicitAnyType - } - val delegatedSuperType = delegatedSuperTypeRef ?: buildImplicitTypeRef() + superTypeRefs.ifEmpty { + superTypeRefs += implicitAnyType + delegatedSuperTypeRef = implicitAnyType + } + val delegatedSuperType = delegatedSuperTypeRef ?: buildImplicitTypeRef() - annotations += modifiers.annotations - this.superTypeRefs += superTypeRefs - typeRef = delegatedSelfType + annotations += modifiers.annotations + this.superTypeRefs += superTypeRefs + this@buildAnonymousObjectExpression.typeRef = delegatedSelfType - val classWrapper = ClassWrapper( - SpecialNames.NO_NAME_PROVIDED, modifiers, ClassKind.OBJECT, this, - hasPrimaryConstructor = false, - hasSecondaryConstructor = classBody.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(), - hasDefaultConstructor = false, - delegatedSelfTypeRef = delegatedSelfType, - delegatedSuperTypeRef = delegatedSuperType, - superTypeCallEntry = superTypeCallEntry - ) - //parse primary constructor - convertPrimaryConstructor( - primaryConstructor, typeRef.source, classWrapper, delegatedConstructorSource - )?.let { this.declarations += it.firConstructor } - delegateFields?.let { this.declarations += it } + val classWrapper = ClassWrapper( + SpecialNames.NO_NAME_PROVIDED, modifiers, ClassKind.OBJECT, this, + hasPrimaryConstructor = false, + hasSecondaryConstructor = classBody.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(), + hasDefaultConstructor = false, + delegatedSelfTypeRef = delegatedSelfType, + delegatedSuperTypeRef = delegatedSuperType, + superTypeCallEntry = superTypeCallEntry + ) + //parse primary constructor + convertPrimaryConstructor( + primaryConstructor, delegatedSelfType.source, classWrapper, delegatedConstructorSource + )?.let { this.declarations += it.firConstructor } + delegateFields?.let { this.declarations += it } - //parse declarations - classBody?.let { - this.declarations += convertClassBody(it, classWrapper) + //parse declarations + classBody?.let { + this.declarations += convertClassBody(it, classWrapper) + } } } } @@ -659,41 +662,45 @@ class DeclarationsConverter( } annotations += modifiers.annotations initializer = withChildClassName(enumEntryName) { - buildAnonymousObject { - source = enumEntry.toFirSourceElement(FirFakeSourceElementKind.EnumInitializer) - moduleData = baseModuleData - origin = FirDeclarationOrigin.Source - classKind = ClassKind.ENUM_ENTRY - scopeProvider = baseScopeProvider - symbol = FirAnonymousObjectSymbol() - annotations += modifiers.annotations - val enumClassWrapper = ClassWrapper( - enumEntryName, modifiers, ClassKind.ENUM_ENTRY, this, - hasPrimaryConstructor = true, - hasSecondaryConstructor = classBodyNode.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(), - hasDefaultConstructor = false, - delegatedSelfTypeRef = buildResolvedTypeRef { - type = ConeClassLikeTypeImpl( - this@buildAnonymousObject.symbol.toLookupTag(), - emptyArray(), - isNullable = false - ) - }.also { registerSelfType(it) }, - delegatedSuperTypeRef = classWrapper.delegatedSelfTypeRef, - superTypeCallEntry = enumSuperTypeCallEntry - ) - superTypeRefs += enumClassWrapper.delegatedSuperTypeRef - convertPrimaryConstructor( - null, - enumEntry.toFirSourceElement(), - enumClassWrapper, - superTypeCallEntry?.toFirSourceElement(), - isEnumEntry = true - )?.let { declarations += it.firConstructor } - classBodyNode?.also { - // Use ANONYMOUS_OBJECT_NAME for the owner class id of enum entry declarations - withChildClassName(ANONYMOUS_OBJECT_NAME, forceLocalContext = true) { - declarations += convertClassBody(it, enumClassWrapper) + buildAnonymousObjectExpression { + val entrySource = enumEntry.toFirSourceElement(FirFakeSourceElementKind.EnumInitializer) + source = entrySource + anonymousObject = buildAnonymousObject { + source = entrySource + moduleData = baseModuleData + origin = FirDeclarationOrigin.Source + classKind = ClassKind.ENUM_ENTRY + scopeProvider = baseScopeProvider + symbol = FirAnonymousObjectSymbol() + annotations += modifiers.annotations + val enumClassWrapper = ClassWrapper( + enumEntryName, modifiers, ClassKind.ENUM_ENTRY, this, + hasPrimaryConstructor = true, + hasSecondaryConstructor = classBodyNode.getChildNodesByType(SECONDARY_CONSTRUCTOR).isNotEmpty(), + hasDefaultConstructor = false, + delegatedSelfTypeRef = buildResolvedTypeRef { + type = ConeClassLikeTypeImpl( + this@buildAnonymousObject.symbol.toLookupTag(), + emptyArray(), + isNullable = false + ) + }.also { registerSelfType(it) }, + delegatedSuperTypeRef = classWrapper.delegatedSelfTypeRef, + superTypeCallEntry = enumSuperTypeCallEntry + ) + superTypeRefs += enumClassWrapper.delegatedSuperTypeRef + convertPrimaryConstructor( + null, + enumEntry.toFirSourceElement(), + enumClassWrapper, + superTypeCallEntry?.toFirSourceElement(), + isEnumEntry = true + )?.let { declarations += it.firConstructor } + classBodyNode?.also { + // Use ANONYMOUS_OBJECT_NAME for the owner class id of enum entry declarations + withChildClassName(ANONYMOUS_OBJECT_NAME, forceLocalContext = true) { + declarations += convertClassBody(it, enumClassWrapper) + } } } } 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 1bb059f7528..db77f399310 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 @@ -758,43 +758,48 @@ open class RawFirBuilder( } extractAnnotationsTo(this) initializer = withChildClassName(nameAsSafeName) { - buildAnonymousObject { - source = toFirSourceElement(FirFakeSourceElementKind.EnumInitializer) - moduleData = baseModuleData - origin = FirDeclarationOrigin.Source - classKind = ClassKind.ENUM_ENTRY - scopeProvider = this@RawFirBuilder.baseScopeProvider - symbol = FirAnonymousObjectSymbol() + buildAnonymousObjectExpression { + val enumEntrySource = toFirSourceElement(FirFakeSourceElementKind.EnumInitializer) + source = enumEntrySource + anonymousObject = buildAnonymousObject { + source = enumEntrySource + moduleData = baseModuleData + origin = FirDeclarationOrigin.Source + classKind = ClassKind.ENUM_ENTRY + scopeProvider = this@RawFirBuilder.baseScopeProvider + symbol = FirAnonymousObjectSymbol() - extractAnnotationsTo(this) - val delegatedEntrySelfType = buildResolvedTypeRef { - type = ConeClassLikeTypeImpl(this@buildAnonymousObject.symbol.toLookupTag(), emptyArray(), isNullable = false) - } - registerSelfType(delegatedEntrySelfType) + extractAnnotationsTo(this) + val delegatedEntrySelfType = buildResolvedTypeRef { + type = + ConeClassLikeTypeImpl(this@buildAnonymousObject.symbol.toLookupTag(), emptyArray(), isNullable = false) + } + registerSelfType(delegatedEntrySelfType) - superTypeRefs += delegatedEnumSelfTypeRef - val superTypeCallEntry = superTypeListEntries.firstIsInstanceOrNull() - val correctedEnumSelfTypeRef = buildResolvedTypeRef { - source = superTypeCallEntry?.calleeExpression?.typeReference?.toFirSourceElement() - type = delegatedEnumSelfTypeRef.type - } - declarations += primaryConstructor.toFirConstructor( - superTypeCallEntry, - correctedEnumSelfTypeRef, - delegatedEntrySelfType, - owner = ktEnumEntry, - typeParameters - ) - // Use ANONYMOUS_OBJECT_NAME for the owner class id for enum entry declarations (see KT-42351) - withChildClassName(ANONYMOUS_OBJECT_NAME, forceLocalContext = true) { - for (declaration in ktEnumEntry.declarations) { - declarations += declaration.toFirDeclaration( - correctedEnumSelfTypeRef, - delegatedSelfType = delegatedEntrySelfType, - ktEnumEntry, - ownerClassBuilder = this, - ownerTypeParameters = emptyList() - ) + superTypeRefs += delegatedEnumSelfTypeRef + val superTypeCallEntry = superTypeListEntries.firstIsInstanceOrNull() + val correctedEnumSelfTypeRef = buildResolvedTypeRef { + source = superTypeCallEntry?.calleeExpression?.typeReference?.toFirSourceElement() + type = delegatedEnumSelfTypeRef.type + } + declarations += primaryConstructor.toFirConstructor( + superTypeCallEntry, + correctedEnumSelfTypeRef, + delegatedEntrySelfType, + owner = ktEnumEntry, + typeParameters + ) + // Use ANONYMOUS_OBJECT_NAME for the owner class id for enum entry declarations (see KT-42351) + withChildClassName(ANONYMOUS_OBJECT_NAME, forceLocalContext = true) { + for (declaration in ktEnumEntry.declarations) { + declarations += declaration.toFirDeclaration( + correctedEnumSelfTypeRef, + delegatedSelfType = delegatedEntrySelfType, + ktEnumEntry, + ownerClassBuilder = this, + ownerTypeParameters = emptyList() + ) + } } } } @@ -943,37 +948,39 @@ open class RawFirBuilder( override fun visitObjectLiteralExpression(expression: KtObjectLiteralExpression, data: Unit): FirElement { val objectDeclaration = expression.objectDeclaration return withChildClassName(ANONYMOUS_OBJECT_NAME, forceLocalContext = true) { - buildAnonymousObject { - source = objectDeclaration.toFirSourceElement() - moduleData = baseModuleData - origin = FirDeclarationOrigin.Source - classKind = ClassKind.OBJECT - scopeProvider = baseScopeProvider - symbol = FirAnonymousObjectSymbol() - context.applyToActualCapturedTypeParameters(false) { - typeParameters += buildOuterClassTypeParameterRef { symbol = it } - } - val delegatedSelfType = objectDeclaration.toDelegatedSelfType(this) - registerSelfType(delegatedSelfType) - objectDeclaration.extractAnnotationsTo(this) - val delegatedSuperType = objectDeclaration.extractSuperTypeListEntriesTo( - this, - delegatedSelfType, - null, - ClassKind.CLASS, - containerTypeParameters = emptyList() - ) - typeRef = delegatedSelfType - - - for (declaration in objectDeclaration.declarations) { - declarations += declaration.toFirDeclaration( - delegatedSuperType, + buildAnonymousObjectExpression { + val sourceElement = objectDeclaration.toFirSourceElement() + source = sourceElement + anonymousObject = buildAnonymousObject { + source = sourceElement + moduleData = baseModuleData + origin = FirDeclarationOrigin.Source + classKind = ClassKind.OBJECT + scopeProvider = baseScopeProvider + symbol = FirAnonymousObjectSymbol() + context.applyToActualCapturedTypeParameters(false) { + typeParameters += buildOuterClassTypeParameterRef { symbol = it } } + val delegatedSelfType = objectDeclaration.toDelegatedSelfType(this) + registerSelfType(delegatedSelfType) + objectDeclaration.extractAnnotationsTo(this) + val delegatedSuperType = objectDeclaration.extractSuperTypeListEntriesTo( + this, delegatedSelfType, - owner = objectDeclaration, - ownerClassBuilder = this, - ownerTypeParameters = emptyList() + null, + ClassKind.CLASS, + containerTypeParameters = emptyList() ) + this@buildAnonymousObjectExpression.typeRef = delegatedSelfType + + for (declaration in objectDeclaration.declarations) { + declarations += declaration.toFirDeclaration( + delegatedSuperType, + delegatedSelfType, + owner = objectDeclaration, + ownerClassBuilder = this, + ownerTypeParameters = emptyList() + ) + } } } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index 771871a663d..46c5841c6a5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -118,9 +118,14 @@ fun FirRegularClass.defaultType(): ConeClassLikeTypeImpl { } fun FirAnonymousObject.defaultType(): ConeClassLikeType { - return this.typeRef.coneTypeSafe() ?: ConeClassLikeTypeImpl( + return ConeClassLikeTypeImpl( symbol.toLookupTag(), - emptyArray(), + typeParameters.map { + ConeTypeParameterTypeImpl( + it.symbol.toLookupTag(), + isNullable = false + ) + }.toTypedArray(), isNullable = false ) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index 6976fb92c08..6d6011c8518 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -309,6 +309,10 @@ abstract class FirDataFlowAnalyzer( return controlFlowGraph } + fun exitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression) { + graphBuilder.exitAnonymousObjectExpression(anonymousObjectExpression).mergeIncomingFlow() + } + // ----------------------------------- Value parameters (and it's defaults) ----------------------------------- fun enterValueParameter(valueParameter: FirValueParameter) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt index 1ae6c7bc74b..123f7edd893 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNode.kt @@ -251,6 +251,12 @@ class AnonymousObjectExitNode(owner: ControlFlowGraph, override val fir: FirAnon } } +class AnonymousObjectExpressionExitNode(owner: ControlFlowGraph, override val fir: FirAnonymousObjectExpression, level: Int, id: Int) : CFGNode(owner, level, id) { + override fun accept(visitor: ControlFlowGraphVisitor, data: D): R { + return visitor.visitAnonymousObjectExpressionExitNode(this, data) + } +} + // ----------------------------------- Initialization ----------------------------------- class PartOfClassInitializationNode(owner: ControlFlowGraph, override val fir: FirControlFlowGraphOwner, level: Int, id: Int) : CFGNodeWithCfgOwner(owner, level, id) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt index a664bdcba26..48c8b8347c2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/CFGNodeRenderer.kt @@ -108,6 +108,7 @@ fun CFGNode<*>.render(): String = is ClassExitNode -> "Exit class ${owner.name}" is LocalClassExitNode -> "Exit local class ${owner.name}" is AnonymousObjectExitNode -> "Exit anonymous object" + is AnonymousObjectExpressionExitNode -> "Exit anonymous object expression" is ContractDescriptionEnterNode -> "Enter contract description" diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt index 0d79cb5b382..c9b1027b822 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt @@ -440,6 +440,12 @@ class ControlFlowGraphBuilder { return node to graph } + fun exitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression): AnonymousObjectExpressionExitNode { + return createAnonymousObjectExpressionExitNode(anonymousObjectExpression).also { + addNewSimpleNodeIfPossible(it) + } + } + fun visitLocalClassFunctions(klass: FirClass<*>, node: CFGNodeWithCfgOwner<*>) { klass.declarations.filterIsInstance>().forEach { function -> val functionGraph = function.controlFlowGraphReference?.controlFlowGraph diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt index 27a082f431e..f9744328edd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphNodeBuilder.kt @@ -224,6 +224,9 @@ fun ControlFlowGraphBuilder.createPostponedLambdaEnterNode(fir: FirAnonymousFunc fun ControlFlowGraphBuilder.createAnonymousObjectExitNode(fir: FirAnonymousObject): AnonymousObjectExitNode = AnonymousObjectExitNode(currentGraph, fir, levelCounter, createId()) +fun ControlFlowGraphBuilder.createAnonymousObjectExpressionExitNode(fir: FirAnonymousObjectExpression): AnonymousObjectExpressionExitNode = + AnonymousObjectExpressionExitNode(currentGraph, fir, levelCounter, createId()) + fun ControlFlowGraphBuilder.createUnionFunctionCallArgumentsNode(fir: FirElement): UnionFunctionCallArgumentsNode = UnionFunctionCallArgumentsNode(currentGraph, fir, levelCounter, createId()) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt index 3277bb76ee8..2bc77e107c5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphVisitor.kt @@ -52,6 +52,10 @@ abstract class ControlFlowGraphVisitor { return visitNode(node, data) } + open fun visitAnonymousObjectExpressionExitNode(node: AnonymousObjectExpressionExitNode, data: D): R { + return visitNode(node, data) + } + open fun visitClassEnterNode(node: ClassEnterNode, data: D): R { return visitNode(node, data) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt index 7b09877ea5e..5132baeb70d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSupertypesResolution.kt @@ -137,7 +137,7 @@ open class FirApplySupertypesTransformer( override fun transformAnonymousObject(anonymousObject: FirAnonymousObject, data: Any?): FirStatement { applyResolvedSupertypesToClass(anonymousObject) - return super.transformAnonymousObject(anonymousObject, data) + return anonymousObject.transformChildren(this, data) as FirAnonymousObject } private fun getResolvedSupertypeRefs(classLikeDeclaration: FirClassLikeDeclaration<*>): List { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt index a87db7c9004..c472da37569 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirBodyResolveTransformer.kt @@ -271,6 +271,13 @@ open class FirBodyResolveTransformer( return declarationsTransformer.transformAnonymousObject(anonymousObject, data) } + override fun transformAnonymousObjectExpression( + anonymousObjectExpression: FirAnonymousObjectExpression, + data: ResolutionMode + ): FirStatement { + return expressionsTransformer.transformAnonymousObjectExpression(anonymousObjectExpression, data) + } + override fun transformSimpleFunction( simpleFunction: FirSimpleFunction, data: ResolutionMode diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index d14b5101740..678264a7977 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -422,12 +422,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor ) } dataFlowAnalyzer.enterClass() - if (anonymousObject.typeRef !is FirResolvedTypeRef) { - anonymousObject.resultType = buildResolvedTypeRef { - source = anonymousObject.source - this.type = anonymousObject.defaultType() - } - } val result = context.withAnonymousObject(anonymousObject, components) { transformDeclarationContent(anonymousObject, data) as FirAnonymousObject } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index e3e0d94a202..d42746945b6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -1063,6 +1063,21 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform return stringConcatenationCall } + override fun transformAnonymousObjectExpression( + anonymousObjectExpression: FirAnonymousObjectExpression, + data: ResolutionMode + ): FirStatement { + anonymousObjectExpression.transformAnonymousObject(transformer, data) + if (anonymousObjectExpression.typeRef !is FirResolvedTypeRef) { + anonymousObjectExpression.resultType = buildResolvedTypeRef { + source = anonymousObjectExpression.source + this.type = anonymousObjectExpression.anonymousObject.defaultType() + } + } + dataFlowAnalyzer.exitAnonymousObjectExpression(anonymousObjectExpression) + return anonymousObjectExpression + } + // ------------------------------------------------------------------------------------------------ internal fun storeTypeFromCallee(access: T) where T : FirQualifiedAccess, T : FirExpression { diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirAnonymousObject.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirAnonymousObject.kt index ddc213c5bf6..b16a2d2ff73 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirAnonymousObject.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirAnonymousObject.kt @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirModuleData import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall -import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference import org.jetbrains.kotlin.fir.scopes.FirScopeProvider import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol @@ -22,7 +21,7 @@ import org.jetbrains.kotlin.fir.visitors.* * DO NOT MODIFY IT MANUALLY */ -abstract class FirAnonymousObject : FirClass, FirControlFlowGraphOwner, FirExpression() { +abstract class FirAnonymousObject : FirClass(), FirControlFlowGraphOwner { abstract override val source: FirSourceElement? abstract override val moduleData: FirModuleData abstract override val resolvePhase: FirResolvePhase @@ -35,7 +34,6 @@ abstract class FirAnonymousObject : FirClass, FirControlFlow abstract override val annotations: List abstract override val scopeProvider: FirScopeProvider abstract override val controlFlowGraphReference: FirControlFlowGraphReference? - abstract override val typeRef: FirTypeRef abstract override val symbol: FirAnonymousObjectSymbol override fun accept(visitor: FirVisitor, data: D): R = visitor.visitAnonymousObject(this, data) @@ -50,8 +48,6 @@ abstract class FirAnonymousObject : FirClass, FirControlFlow abstract override fun replaceControlFlowGraphReference(newControlFlowGraphReference: FirControlFlowGraphReference?) - abstract override fun replaceTypeRef(newTypeRef: FirTypeRef) - abstract override fun transformTypeParameters(transformer: FirTransformer, data: D): FirAnonymousObject abstract override fun transformSuperTypeRefs(transformer: FirTransformer, data: D): FirAnonymousObject diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClass.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClass.kt index 3c9bd975ff7..626593523cd 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClass.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClass.kt @@ -21,19 +21,19 @@ import org.jetbrains.kotlin.fir.visitors.* * DO NOT MODIFY IT MANUALLY */ -sealed interface FirClass> : FirClassLikeDeclaration, FirStatement, FirTypeParameterRefsOwner { - override val source: FirSourceElement? - override val moduleData: FirModuleData - override val resolvePhase: FirResolvePhase - override val origin: FirDeclarationOrigin - override val attributes: FirDeclarationAttributes - override val typeParameters: List - override val symbol: FirClassSymbol - val classKind: ClassKind - val superTypeRefs: List - val declarations: List - override val annotations: List - val scopeProvider: FirScopeProvider +sealed class FirClass> : FirClassLikeDeclaration(), FirStatement, FirTypeParameterRefsOwner { + abstract override val source: FirSourceElement? + abstract override val moduleData: FirModuleData + abstract override val resolvePhase: FirResolvePhase + abstract override val origin: FirDeclarationOrigin + abstract override val attributes: FirDeclarationAttributes + abstract override val typeParameters: List + abstract override val symbol: FirClassSymbol + abstract val classKind: ClassKind + abstract val superTypeRefs: List + abstract val declarations: List + abstract override val annotations: List + abstract val scopeProvider: FirScopeProvider override fun accept(visitor: FirVisitor, data: D): R = visitor.visitClass(this, data) @@ -41,15 +41,15 @@ sealed interface FirClass> : FirClassLikeDeclaration, FirStat override fun transform(transformer: FirTransformer, data: D): E = transformer.transformClass(this, data) as E - override fun replaceResolvePhase(newResolvePhase: FirResolvePhase) + abstract override fun replaceResolvePhase(newResolvePhase: FirResolvePhase) - fun replaceSuperTypeRefs(newSuperTypeRefs: List) + abstract fun replaceSuperTypeRefs(newSuperTypeRefs: List) - override fun transformTypeParameters(transformer: FirTransformer, data: D): FirClass + abstract override fun transformTypeParameters(transformer: FirTransformer, data: D): FirClass - fun transformSuperTypeRefs(transformer: FirTransformer, data: D): FirClass + abstract fun transformSuperTypeRefs(transformer: FirTransformer, data: D): FirClass - fun transformDeclarations(transformer: FirTransformer, data: D): FirClass + abstract fun transformDeclarations(transformer: FirTransformer, data: D): FirClass - override fun transformAnnotations(transformer: FirTransformer, data: D): FirClass + abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirClass } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClassLikeDeclaration.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClassLikeDeclaration.kt index 9386c371ba9..637048bdc24 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClassLikeDeclaration.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirClassLikeDeclaration.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.declarations import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirModuleData +import org.jetbrains.kotlin.fir.FirPureAbstractElement import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.FirSymbolOwner import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall @@ -19,14 +20,14 @@ import org.jetbrains.kotlin.fir.visitors.* * DO NOT MODIFY IT MANUALLY */ -sealed interface FirClassLikeDeclaration> : FirAnnotatedDeclaration, FirStatement, FirSymbolOwner { - override val source: FirSourceElement? - override val moduleData: FirModuleData - override val resolvePhase: FirResolvePhase - override val origin: FirDeclarationOrigin - override val attributes: FirDeclarationAttributes - override val annotations: List - override val symbol: FirClassLikeSymbol +sealed class FirClassLikeDeclaration> : FirPureAbstractElement(), FirAnnotatedDeclaration, FirStatement, FirSymbolOwner { + abstract override val source: FirSourceElement? + abstract override val moduleData: FirModuleData + abstract override val resolvePhase: FirResolvePhase + abstract override val origin: FirDeclarationOrigin + abstract override val attributes: FirDeclarationAttributes + abstract override val annotations: List + abstract override val symbol: FirClassLikeSymbol override fun accept(visitor: FirVisitor, data: D): R = visitor.visitClassLikeDeclaration(this, data) @@ -34,7 +35,7 @@ sealed interface FirClassLikeDeclaration> : FirAn override fun transform(transformer: FirTransformer, data: D): E = transformer.transformClassLikeDeclaration(this, data) as E - override fun replaceResolvePhase(newResolvePhase: FirResolvePhase) + abstract override fun replaceResolvePhase(newResolvePhase: FirResolvePhase) - override fun transformAnnotations(transformer: FirTransformer, data: D): FirClassLikeDeclaration + abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirClassLikeDeclaration } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirRegularClass.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirRegularClass.kt index 87e6fcaefc1..075446dc3cb 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirRegularClass.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirRegularClass.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.declarations import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirModuleData -import org.jetbrains.kotlin.fir.FirPureAbstractElement import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference @@ -23,7 +22,7 @@ import org.jetbrains.kotlin.fir.visitors.* * DO NOT MODIFY IT MANUALLY */ -abstract class FirRegularClass : FirPureAbstractElement(), FirMemberDeclaration, FirTypeParameterRefsOwner, FirControlFlowGraphOwner, FirClass { +abstract class FirRegularClass : FirMemberDeclaration, FirTypeParameterRefsOwner, FirControlFlowGraphOwner, FirClass() { abstract override val source: FirSourceElement? abstract override val moduleData: FirModuleData abstract override val resolvePhase: FirResolvePhase diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirTypeAlias.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirTypeAlias.kt index 2e5bb6d31b0..3574f723b42 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirTypeAlias.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/FirTypeAlias.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.fir.declarations import org.jetbrains.kotlin.fir.FirElement import org.jetbrains.kotlin.fir.FirModuleData -import org.jetbrains.kotlin.fir.FirPureAbstractElement import org.jetbrains.kotlin.fir.FirSourceElement import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol @@ -20,7 +19,7 @@ import org.jetbrains.kotlin.fir.visitors.* * DO NOT MODIFY IT MANUALLY */ -abstract class FirTypeAlias : FirPureAbstractElement(), FirClassLikeDeclaration, FirMemberDeclaration, FirTypeParametersOwner { +abstract class FirTypeAlias : FirClassLikeDeclaration(), FirMemberDeclaration, FirTypeParametersOwner { abstract override val source: FirSourceElement? abstract override val moduleData: FirModuleData abstract override val resolvePhase: FirResolvePhase diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirAnonymousObjectBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirAnonymousObjectBuilder.kt index e8c355970ac..86ed6346613 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirAnonymousObjectBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/builder/FirAnonymousObjectBuilder.kt @@ -21,12 +21,10 @@ import org.jetbrains.kotlin.fir.declarations.builder.FirClassBuilder import org.jetbrains.kotlin.fir.declarations.builder.FirDeclarationBuilder import org.jetbrains.kotlin.fir.declarations.impl.FirAnonymousObjectImpl import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall -import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference import org.jetbrains.kotlin.fir.scopes.FirScopeProvider import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol import org.jetbrains.kotlin.fir.types.FirTypeRef -import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl import org.jetbrains.kotlin.fir.visitors.* /* @@ -35,7 +33,7 @@ import org.jetbrains.kotlin.fir.visitors.* */ @FirBuilderDsl -class FirAnonymousObjectBuilder : FirDeclarationBuilder, FirClassBuilder, FirAnnotationContainerBuilder, FirExpressionBuilder { +class FirAnonymousObjectBuilder : FirDeclarationBuilder, FirClassBuilder, FirAnnotationContainerBuilder { override var source: FirSourceElement? = null override lateinit var moduleData: FirModuleData override var resolvePhase: FirResolvePhase = FirResolvePhase.RAW_FIR @@ -47,7 +45,6 @@ class FirAnonymousObjectBuilder : FirDeclarationBuilder, FirClassBuilder, FirAnn override val declarations: MutableList = mutableListOf() override val annotations: MutableList = mutableListOf() override lateinit var scopeProvider: FirScopeProvider - override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null) lateinit var symbol: FirAnonymousObjectSymbol override fun build(): FirAnonymousObject { @@ -63,7 +60,6 @@ class FirAnonymousObjectBuilder : FirDeclarationBuilder, FirClassBuilder, FirAnn declarations, annotations, scopeProvider, - typeRef, symbol, ) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt index 42b8f144a1d..77f6d58676c 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/declarations/impl/FirAnonymousObjectImpl.kt @@ -38,7 +38,6 @@ internal class FirAnonymousObjectImpl( override val declarations: MutableList, override val annotations: MutableList, override val scopeProvider: FirScopeProvider, - override var typeRef: FirTypeRef, override val symbol: FirAnonymousObjectSymbol, ) : FirAnonymousObject() { override var controlFlowGraphReference: FirControlFlowGraphReference? = null @@ -53,7 +52,6 @@ internal class FirAnonymousObjectImpl( declarations.forEach { it.accept(visitor, data) } annotations.forEach { it.accept(visitor, data) } controlFlowGraphReference?.accept(visitor, data) - typeRef.accept(visitor, data) } override fun transformChildren(transformer: FirTransformer, data: D): FirAnonymousObjectImpl { @@ -62,7 +60,6 @@ internal class FirAnonymousObjectImpl( transformDeclarations(transformer, data) transformAnnotations(transformer, data) controlFlowGraphReference = controlFlowGraphReference?.transform(transformer, data) - typeRef = typeRef.transform(transformer, data) return this } @@ -98,8 +95,4 @@ internal class FirAnonymousObjectImpl( override fun replaceControlFlowGraphReference(newControlFlowGraphReference: FirControlFlowGraphReference?) { controlFlowGraphReference = newControlFlowGraphReference } - - override fun replaceTypeRef(newTypeRef: FirTypeRef) { - typeRef = newTypeRef - } } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirAnonymousObjectExpression.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirAnonymousObjectExpression.kt new file mode 100644 index 00000000000..71a628ed415 --- /dev/null +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirAnonymousObjectExpression.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.expressions + +import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirSourceElement +import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +abstract class FirAnonymousObjectExpression : FirExpression() { + abstract override val source: FirSourceElement? + abstract override val typeRef: FirTypeRef + abstract override val annotations: List + abstract val anonymousObject: FirAnonymousObject + + override fun accept(visitor: FirVisitor, data: D): R = visitor.visitAnonymousObjectExpression(this, data) + + @Suppress("UNCHECKED_CAST") + override fun transform(transformer: FirTransformer, data: D): E = + transformer.transformAnonymousObjectExpression(this, data) as E + + abstract override fun replaceTypeRef(newTypeRef: FirTypeRef) + + abstract override fun transformAnnotations(transformer: FirTransformer, data: D): FirAnonymousObjectExpression + + abstract fun transformAnonymousObject(transformer: FirTransformer, data: D): FirAnonymousObjectExpression +} diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt index 8974a8772dc..f090dfa9e80 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirTransformer.kt @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject +import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression import org.jetbrains.kotlin.fir.diagnostics.FirDiagnosticHolder import org.jetbrains.kotlin.fir.declarations.FirImport import org.jetbrains.kotlin.fir.declarations.FirResolvedImport @@ -302,6 +303,10 @@ abstract class FirTransformer : FirVisitor() { return transformElement(anonymousObject, data) } + open fun transformAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression, data: D): FirStatement { + return transformElement(anonymousObjectExpression, data) + } + open fun transformDiagnosticHolder(diagnosticHolder: FirDiagnosticHolder, data: D): FirDiagnosticHolder { return transformElement(diagnosticHolder, data) } @@ -810,6 +815,10 @@ abstract class FirTransformer : FirVisitor() { return transformAnonymousObject(anonymousObject, data) } + final override fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression, data: D): FirStatement { + return transformAnonymousObjectExpression(anonymousObjectExpression, data) + } + final override fun visitDiagnosticHolder(diagnosticHolder: FirDiagnosticHolder, data: D): FirDiagnosticHolder { return transformDiagnosticHolder(diagnosticHolder, data) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt index ad93dd6f76f..eb050b00139 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitor.kt @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject +import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression import org.jetbrains.kotlin.fir.diagnostics.FirDiagnosticHolder import org.jetbrains.kotlin.fir.declarations.FirImport import org.jetbrains.kotlin.fir.declarations.FirResolvedImport @@ -221,6 +222,8 @@ abstract class FirVisitor { open fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: D): R = visitElement(anonymousObject, data) + open fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression, data: D): R = visitElement(anonymousObjectExpression, data) + open fun visitDiagnosticHolder(diagnosticHolder: FirDiagnosticHolder, data: D): R = visitElement(diagnosticHolder, data) open fun visitImport(import: FirImport, data: D): R = visitElement(import, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt index 3fdb7b8ff70..d0ef6c7d75f 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/visitors/FirVisitorVoid.kt @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject +import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression import org.jetbrains.kotlin.fir.diagnostics.FirDiagnosticHolder import org.jetbrains.kotlin.fir.declarations.FirImport import org.jetbrains.kotlin.fir.declarations.FirResolvedImport @@ -301,6 +302,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitElement(anonymousObject) } + open fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression) { + visitElement(anonymousObjectExpression) + } + open fun visitDiagnosticHolder(diagnosticHolder: FirDiagnosticHolder) { visitElement(diagnosticHolder) } @@ -809,6 +814,10 @@ abstract class FirVisitorVoid : FirVisitor() { visitAnonymousObject(anonymousObject) } + final override fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression, data: Nothing?) { + visitAnonymousObjectExpression(anonymousObjectExpression) + } + final override fun visitDiagnosticHolder(diagnosticHolder: FirDiagnosticHolder, data: Nothing?) { visitDiagnosticHolder(diagnosticHolder) } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index e3a244d3304..59910d476bc 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -479,6 +479,10 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM } } + override fun visitAnonymousObjectExpression(anonymousObjectExpression: FirAnonymousObjectExpression) { + anonymousObjectExpression.anonymousObject.accept(this) + } + override fun visitAnonymousObject(anonymousObject: FirAnonymousObject) { anonymousObject.annotations.renderAnnotations() print("object : ") diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt new file mode 100644 index 00000000000..f33a0a6aa6b --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.expressions.builder + +import org.jetbrains.kotlin.fir.FirSourceElement +import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder +import org.jetbrains.kotlin.fir.builder.FirBuilderDsl +import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression +import org.jetbrains.kotlin.fir.expressions.impl.FirAnonymousObjectExpressionImpl +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract + +@FirBuilderDsl +class FirAnonymousObjectExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder { + override var source: FirSourceElement? = null + override var typeRef: FirTypeRef = FirImplicitTypeRefImpl(null) + lateinit var anonymousObject: FirAnonymousObject + + override val annotations: MutableList + get() = error("Should not be called") + + override fun build(): FirAnonymousObjectExpression { + return FirAnonymousObjectExpressionImpl( + source, + typeRef, + anonymousObject, + ) + } + +} + +@OptIn(ExperimentalContracts::class) +inline fun buildAnonymousObjectExpression(init: FirAnonymousObjectExpressionBuilder.() -> Unit): FirAnonymousObjectExpression { + contract { + callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE) + } + return FirAnonymousObjectExpressionBuilder().apply(init).build() +} diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAnonymousObjectExpressionImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAnonymousObjectExpressionImpl.kt new file mode 100644 index 00000000000..ccfa9194235 --- /dev/null +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/impl/FirAnonymousObjectExpressionImpl.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.fir.expressions.impl + +import org.jetbrains.kotlin.fir.FirSourceElement +import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject +import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression +import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.visitors.* + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +internal class FirAnonymousObjectExpressionImpl( + override val source: FirSourceElement?, + override var typeRef: FirTypeRef, + override var anonymousObject: FirAnonymousObject, +) : FirAnonymousObjectExpression() { + override val annotations: List + get() = anonymousObject.annotations + + override fun acceptChildren(visitor: FirVisitor, data: D) { + typeRef.accept(visitor, data) + anonymousObject.accept(visitor, data) + } + + override fun transformChildren(transformer: FirTransformer, data: D): FirAnonymousObjectExpressionImpl { + typeRef = typeRef.transform(transformer, data) + transformAnonymousObject(transformer, data) + return this + } + + override fun transformAnnotations(transformer: FirTransformer, data: D): FirAnonymousObjectExpressionImpl { + return this + } + + override fun transformAnonymousObject(transformer: FirTransformer, data: D): FirAnonymousObjectExpressionImpl { + anonymousObject = anonymousObject.transform(transformer, data) + return this + } + + override fun replaceTypeRef(newTypeRef: FirTypeRef) { + typeRef = newTypeRef + } +} diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt index 43122176a04..4846b92d1d9 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt @@ -337,7 +337,6 @@ object BuilderConfigurator : AbstractBuilderConfigurator(FirTree val elementsWithDefaultTypeRef = listOf( thisReceiverExpression, callableReferenceAccess, - anonymousObject, qualifiedAccessExpression, functionCall, anonymousFunction, diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt index 73d20dacd97..722d4efe654 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/FirTreeBuilder.kt @@ -59,7 +59,9 @@ object FirTreeBuilder : AbstractFirTreeBuilder() { val file = element("File", Declaration, annotatedDeclaration) val anonymousFunction = element("AnonymousFunction", Declaration, function, expression, typeParametersOwner) - val anonymousObject = element("AnonymousObject", Declaration, klass, controlFlowGraphOwner, expression) + + val anonymousObject = element("AnonymousObject", Declaration, klass, controlFlowGraphOwner) + val anonymousObjectExpression = element("AnonymousObjectExpression", Expression, expression) val diagnosticHolder = element("DiagnosticHolder", Diagnostics) diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt index e8becdb51f7..dcb3546e0da 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt @@ -36,6 +36,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() } impl(anonymousObject) + noImpl(anonymousObjectExpression) impl(typeAlias) @@ -507,7 +508,6 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() "FirTypeProjectionWithVarianceImpl", "FirCallableReferenceAccessImpl", "FirThisReceiverExpressionImpl", - "FirAnonymousObjectImpl", "FirQualifiedAccessExpressionImpl", "FirFunctionCallImpl", "FirAnonymousFunctionImpl", diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index 5961a611821..790aac7309d 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -269,6 +269,10 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +symbol("FirAnonymousObjectSymbol") } + anonymousObjectExpression.configure { + +field(anonymousObject).withTransform() + } + typeAlias.configure { +typeParameters parentArg(classLikeDeclaration, "F", typeAlias)