From adfd478361259cd9323113ac92df54732e4e565b Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 16 Apr 2020 17:45:19 +0300 Subject: [PATCH] [FIR] Hold all containers in body resolve context, not only last one --- .../FirAbstractBodyResolveTransformer.kt | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt index e0b65140c7c..61e6e39e28c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirAbstractBodyResolveTransformer.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve +import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.persistentListOf import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* @@ -121,18 +122,23 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb @set:PrivateForInline var implicitReceiverStack: MutableImplicitReceiverStack = ImplicitReceiverStackImpl() + val containerIfAny: FirDeclaration? + get() = containers.lastOrNull() + @set:PrivateForInline - var containerIfAny: FirDeclaration? = null + var containers: PersistentList = persistentListOf() val localContextForAnonymousFunctions: MutableMap = mutableMapOf() @OptIn(PrivateForInline::class) inline fun withContainer(declaration: FirDeclaration, crossinline f: () -> T): T { - val prevContainer = containerIfAny - containerIfAny = declaration - val result = f() - containerIfAny = prevContainer - return result + val oldContainers = containers + containers = containers.add(declaration) + return try { + f() + } finally { + containers = oldContainers + } } @OptIn(PrivateForInline::class) @@ -207,7 +213,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb file = this@BodyResolveContext.file implicitReceiverStack = this@BodyResolveContext.implicitReceiverStack localContextForAnonymousFunctions.putAll(this@BodyResolveContext.localContextForAnonymousFunctions) - containerIfAny = this@BodyResolveContext.containerIfAny + containers = this@BodyResolveContext.containers } }