FIR: introduce separate companion object resolve context
Before this commit, during the resolve of companion objects we used the same context than for any nested class. However, during companion object resolve we should not have companion object receiver itself accessible in any case (in particular, it should not be accessible in constructor). So in this commit we introduced separate context for this purpose.
This commit is contained in:
@@ -143,6 +143,7 @@ typealias TowerDataContextForAnonymousFunctions = Map<FirAnonymousFunctionSymbol
|
||||
|
||||
class FirTowerDataContextsForClassParts(
|
||||
val forNestedClasses: FirTowerDataContext,
|
||||
val forCompanionObject: FirTowerDataContext,
|
||||
val forConstructorHeaders: FirTowerDataContext,
|
||||
val primaryConstructorPureParametersScope: FirLocalScope?,
|
||||
val primaryConstructorAllParametersScope: FirLocalScope?,
|
||||
|
||||
+3
@@ -82,6 +82,9 @@ class BodyResolveContext(
|
||||
fun getTowerDataContextForStaticNestedClassesUnsafe(): FirTowerDataContext =
|
||||
firTowerDataContextsForClassParts().forNestedClasses
|
||||
|
||||
fun getTowerDataContextForCompanionUnsafe(): FirTowerDataContext =
|
||||
firTowerDataContextsForClassParts().forCompanionObject
|
||||
|
||||
fun getTowerDataContextForConstructorResolution(): FirTowerDataContext =
|
||||
firTowerDataContextsForClassParts().forConstructorHeaders
|
||||
|
||||
|
||||
+16
-12
@@ -348,7 +348,11 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
return context.withTowerDataCleanup {
|
||||
if (!regularClass.isInner && context.containerIfAny is FirRegularClass) {
|
||||
context.replaceTowerDataContext(
|
||||
context.getTowerDataContextForStaticNestedClassesUnsafe()
|
||||
if (regularClass.isCompanion) {
|
||||
context.getTowerDataContextForCompanionUnsafe()
|
||||
} else {
|
||||
context.getTowerDataContextForStaticNestedClassesUnsafe()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -816,17 +820,16 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
): T = context.withTowerDataCleanup {
|
||||
val towerElementsForClass = components.collectTowerDataElementsForClass(owner, type)
|
||||
|
||||
val staticsAndCompanion =
|
||||
context.towerDataContext
|
||||
.addNonLocalTowerDataElements(towerElementsForClass.superClassesStaticsAndCompanionReceivers)
|
||||
.run {
|
||||
if (towerElementsForClass.companionReceiver != null)
|
||||
addReceiver(null, towerElementsForClass.companionReceiver)
|
||||
else
|
||||
this
|
||||
}
|
||||
.addNonLocalScopeIfNotNull(towerElementsForClass.companionStaticScope)
|
||||
.addNonLocalScopeIfNotNull(towerElementsForClass.staticScope)
|
||||
val base = context.towerDataContext.addNonLocalTowerDataElements(towerElementsForClass.superClassesStaticsAndCompanionReceivers)
|
||||
val statics = base
|
||||
.addNonLocalScopeIfNotNull(towerElementsForClass.companionStaticScope)
|
||||
.addNonLocalScopeIfNotNull(towerElementsForClass.staticScope)
|
||||
|
||||
val companionReceiver = towerElementsForClass.companionReceiver
|
||||
val staticsAndCompanion = if (companionReceiver == null) statics else base
|
||||
.addReceiver(null, companionReceiver)
|
||||
.addNonLocalScopeIfNotNull(towerElementsForClass.companionStaticScope)
|
||||
.addNonLocalScopeIfNotNull(towerElementsForClass.staticScope)
|
||||
|
||||
val typeParameterScope = (owner as? FirRegularClass)?.let(this::createTypeParameterScope)
|
||||
|
||||
@@ -856,6 +859,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
|
||||
val newContexts = FirTowerDataContextsForClassParts(
|
||||
newTowerDataContextForStaticNestedClasses,
|
||||
statics,
|
||||
scopeForConstructorHeader,
|
||||
primaryConstructorPureParametersScope,
|
||||
primaryConstructorAllParametersScope
|
||||
|
||||
Reference in New Issue
Block a user