diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot b/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot index e53c22cbeab..142575b4e1d 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot +++ b/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot @@ -17,81 +17,75 @@ digraph secondaryConstructorCfg_kt { 20 [label="Enter function " style="filled" fillcolor=red]; 22 [label="Access variable R|/p0|"]; 23 [label="Delegated constructor call: this(...)"]; - subgraph cluster_2 { - color=blue - 24 [label="Enter block"]; - 25 [label="Access variable R|/p1|"]; - 26 [label="Assignment: R|/B.p3|"]; - 27 [label="Exit block"]; - } - 21 [label="Exit function " style="filled" fillcolor=red style="filled" fillcolor=gray]; + 24 [label="Access variable R|/p1|"]; + 25 [label="Assignment: R|/B.p3|"]; + 21 [label="Exit function " style="filled" fillcolor=red]; } 20 -> {22}; 22 -> {23}; 23 -> {24}; 24 -> {25}; - 25 -> {26}; - 26 -> {27}; + 25 -> {21}; - subgraph cluster_3 { + subgraph cluster_2 { color=red - 37 [label="Enter class B" style="filled" fillcolor=red]; - subgraph cluster_4 { + 35 [label="Enter class B" style="filled" fillcolor=red]; + subgraph cluster_3 { color=blue 16 [label="Enter function setter" style="filled" fillcolor=red]; 17 [label="Exit function setter" style="filled" fillcolor=red]; } - subgraph cluster_5 { + subgraph cluster_4 { color=blue 14 [label="Enter function getter" style="filled" fillcolor=red]; 15 [label="Exit function getter" style="filled" fillcolor=red]; } - subgraph cluster_6 { + subgraph cluster_5 { color=blue 8 [label="Enter function getter" style="filled" fillcolor=red]; 9 [label="Exit function getter" style="filled" fillcolor=red]; } - subgraph cluster_7 { + subgraph cluster_6 { color=blue 3 [label="Enter function getter" style="filled" fillcolor=red]; 4 [label="Exit function getter" style="filled" fillcolor=red]; } - subgraph cluster_8 { + subgraph cluster_7 { color=blue 5 [label="Enter property" style="filled" fillcolor=red]; 7 [label="Access variable R|/p0|"]; 6 [label="Exit property" style="filled" fillcolor=red]; } - subgraph cluster_9 { + subgraph cluster_8 { color=blue 10 [label="Enter property" style="filled" fillcolor=red]; 12 [label="Access variable R|/p0|"]; 13 [label="Access variable R|kotlin/String.length|"]; 11 [label="Exit property" style="filled" fillcolor=red]; } - subgraph cluster_10 { + subgraph cluster_9 { color=blue 18 [label="Enter property" style="filled" fillcolor=red]; 19 [label="Exit property" style="filled" fillcolor=red]; } - subgraph cluster_11 { + subgraph cluster_10 { color=blue - 28 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_12 { + 26 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_11 { color=blue - 30 [label="Enter block"]; - 31 [label="Access variable R|/p0|"]; - 32 [label="Access variable R|kotlin/String.length|"]; - 33 [label="Assignment: R|/B.p1|"]; - 34 [label="Const: String()"]; - 35 [label="Assignment: R|/B.p3|"]; - 36 [label="Exit block"]; + 28 [label="Enter block"]; + 29 [label="Access variable R|/p0|"]; + 30 [label="Access variable R|kotlin/String.length|"]; + 31 [label="Assignment: R|/B.p1|"]; + 32 [label="Const: String()"]; + 33 [label="Assignment: R|/B.p3|"]; + 34 [label="Exit block"]; } - 29 [label="Exit init block" style="filled" fillcolor=red]; + 27 [label="Exit init block" style="filled" fillcolor=red]; } - 38 [label="Exit class B" style="filled" fillcolor=red]; + 36 [label="Exit class B" style="filled" fillcolor=red]; } - 37 -> {5} [color=green]; + 35 -> {5} [color=green]; 5 -> {7}; 6 -> {10} [color=green]; 7 -> {6}; @@ -102,17 +96,17 @@ digraph secondaryConstructorCfg_kt { 13 -> {11}; 8 -> {9}; 18 -> {19}; - 19 -> {28} [color=green]; + 19 -> {26} [color=green]; 14 -> {15}; 16 -> {17}; - 28 -> {30}; - 29 -> {38} [color=green]; + 26 -> {28}; + 27 -> {36} [color=green]; + 28 -> {29}; + 29 -> {30}; 30 -> {31}; 31 -> {32}; 32 -> {33}; 33 -> {34}; - 34 -> {35}; - 35 -> {36}; - 36 -> {29}; + 34 -> {27}; } 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 bf4547b563e..7249da907ba 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 @@ -305,13 +305,20 @@ class ControlFlowGraphBuilder { // ----------------------------------- Block ----------------------------------- fun enterBlock(block: FirBlock): BlockEnterNode? { - val lastNode = lastNode - return if (lastNode is FunctionEnterNode) { - blocksOfFunctions[block] = lastNode.fir - null - } else { - createBlockEnterNode(block).also { addNewSimpleNode(it) }.also { levelCounter++ } + when (val lastNode = lastNode) { + is FunctionEnterNode -> { + blocksOfFunctions[block] = lastNode.fir + return null + } + is DelegatedConstructorCallNode -> { + val ownerEnterNode = lastNode.owner.enterNode + if (ownerEnterNode is FunctionEnterNode) { + blocksOfFunctions[block] = ownerEnterNode.fir + return null + } + } } + return createBlockEnterNode(block).also { addNewSimpleNode(it) }.also { levelCounter++ } } fun exitBlock(block: FirBlock): CFGNode<*> {