From 5180e1f4a4bab10713830880e5cbac7c114207dd Mon Sep 17 00:00:00 2001 From: pyos Date: Thu, 8 Dec 2022 15:48:09 +0100 Subject: [PATCH] FIR DFA: fix mismatched calls to enter/exitProperty Otherwise the graph stack becomes incorrect. --- .../kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt | 7 +++++-- .../body/resolve/FirDeclarationsResolveTransformer.kt | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) 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 e0203c68e2a..2445647fb60 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 @@ -584,8 +584,11 @@ class ControlFlowGraphBuilder { // ----------------------------------- Property ----------------------------------- + private val FirProperty.hasInitialization: Boolean + get() = initializer != null || delegate != null || hasExplicitBackingField + fun enterProperty(property: FirProperty): PropertyInitializerEnterNode? { - if (property.initializer == null && property.delegate == null && !property.hasExplicitBackingField) return null + if (!property.hasInitialization) return null val graph = ControlFlowGraph(property, "val ${property.name}", ControlFlowGraph.Kind.PropertyInitializer) pushGraph(graph, Mode.PropertyInitializer) @@ -603,7 +606,7 @@ class ControlFlowGraphBuilder { } fun exitProperty(property: FirProperty): Pair? { - if (property.initializer == null && property.delegate == null && !property.hasExplicitBackingField) return null + if (!property.hasInitialization) return null val exitNode = exitTargetsForTry.pop() as PropertyInitializerExitNode popAndAddEdge(exitNode) val graph = popGraph() 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 b676eb3f042..d0a3f4d00b8 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 @@ -135,11 +135,13 @@ open class FirDeclarationsResolveTransformer(transformer: FirAbstractBodyResolve } property.transformReceiverParameter(transformer, ResolutionMode.ContextIndependent) - dataFlowAnalyzer.enterProperty(property) doTransformTypeParameters(property) val shouldResolveEverything = !implicitTypeOnly return withFullBodyResolve { val initializerIsAlreadyResolved = bodyResolveState >= FirPropertyBodyResolveState.INITIALIZER_RESOLVED + if (!initializerIsAlreadyResolved) { + dataFlowAnalyzer.enterProperty(property) + } var backingFieldIsAlreadyResolved = false context.withProperty(property) { context.forPropertyInitializer {