[FIR] Hold all containers in body resolve context, not only last one
This commit is contained in:
+13
-7
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
|
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
|
||||||
|
|
||||||
|
import kotlinx.collections.immutable.PersistentList
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
import org.jetbrains.kotlin.fir.*
|
import org.jetbrains.kotlin.fir.*
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
@@ -121,18 +122,23 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
|||||||
@set:PrivateForInline
|
@set:PrivateForInline
|
||||||
var implicitReceiverStack: MutableImplicitReceiverStack = ImplicitReceiverStackImpl()
|
var implicitReceiverStack: MutableImplicitReceiverStack = ImplicitReceiverStackImpl()
|
||||||
|
|
||||||
|
val containerIfAny: FirDeclaration?
|
||||||
|
get() = containers.lastOrNull()
|
||||||
|
|
||||||
@set:PrivateForInline
|
@set:PrivateForInline
|
||||||
var containerIfAny: FirDeclaration? = null
|
var containers: PersistentList<FirDeclaration> = persistentListOf()
|
||||||
|
|
||||||
val localContextForAnonymousFunctions: MutableMap<FirAnonymousFunctionSymbol, FirLocalContext> = mutableMapOf()
|
val localContextForAnonymousFunctions: MutableMap<FirAnonymousFunctionSymbol, FirLocalContext> = mutableMapOf()
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withContainer(declaration: FirDeclaration, crossinline f: () -> T): T {
|
inline fun <T> withContainer(declaration: FirDeclaration, crossinline f: () -> T): T {
|
||||||
val prevContainer = containerIfAny
|
val oldContainers = containers
|
||||||
containerIfAny = declaration
|
containers = containers.add(declaration)
|
||||||
val result = f()
|
return try {
|
||||||
containerIfAny = prevContainer
|
f()
|
||||||
return result
|
} finally {
|
||||||
|
containers = oldContainers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
@OptIn(PrivateForInline::class)
|
||||||
@@ -207,7 +213,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
|||||||
file = this@BodyResolveContext.file
|
file = this@BodyResolveContext.file
|
||||||
implicitReceiverStack = this@BodyResolveContext.implicitReceiverStack
|
implicitReceiverStack = this@BodyResolveContext.implicitReceiverStack
|
||||||
localContextForAnonymousFunctions.putAll(this@BodyResolveContext.localContextForAnonymousFunctions)
|
localContextForAnonymousFunctions.putAll(this@BodyResolveContext.localContextForAnonymousFunctions)
|
||||||
containerIfAny = this@BodyResolveContext.containerIfAny
|
containers = this@BodyResolveContext.containers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user