[FIR] Fix creating scopes for enum entry initializers
Before we analyzed initializers of enum entry with scope for constructor in implict type mode, so scope was untouchable. Now we analyze them in body resolve phase, so previously we add value parameters to constructors scope, which mess up scope of enum entry initializer
This commit is contained in:
@@ -152,6 +152,7 @@ enum class FirTowerDataMode {
|
||||
NESTED_CLASS,
|
||||
COMPANION_OBJECT,
|
||||
CONSTRUCTOR_HEADER,
|
||||
ENUM_ENTRY,
|
||||
SPECIAL,
|
||||
}
|
||||
|
||||
@@ -160,6 +161,7 @@ class FirTowerDataContextsForClassParts(
|
||||
forNestedClasses: FirTowerDataContext? = null,
|
||||
forCompanionObject: FirTowerDataContext? = null,
|
||||
forConstructorHeaders: FirTowerDataContext? = null,
|
||||
forEnumEntries: FirTowerDataContext? = null,
|
||||
val primaryConstructorPureParametersScope: FirLocalScope? = null,
|
||||
val primaryConstructorAllParametersScope: FirLocalScope? = null,
|
||||
) {
|
||||
@@ -170,6 +172,7 @@ class FirTowerDataContextsForClassParts(
|
||||
modeMap[NESTED_CLASS] = forNestedClasses
|
||||
modeMap[COMPANION_OBJECT] = forCompanionObject
|
||||
modeMap[CONSTRUCTOR_HEADER] = forConstructorHeaders
|
||||
modeMap[ENUM_ENTRY] = forEnumEntries
|
||||
}
|
||||
|
||||
var mode: FirTowerDataMode = MEMBER_DECLARATION
|
||||
|
||||
+12
-1
@@ -418,6 +418,16 @@ class BodyResolveContext(
|
||||
val scopeForConstructorHeader =
|
||||
staticsAndCompanion.addNonLocalScopeIfNotNull(typeParameterScope)
|
||||
|
||||
/*
|
||||
* Scope for enum entries is equal to initial scope for constructor header
|
||||
*
|
||||
* The only difference that we add value parameters to local scope for constructors
|
||||
* and should not do this for enum entries
|
||||
*/
|
||||
|
||||
@Suppress("UnnecessaryVariable")
|
||||
val scopeForEnumEntries = scopeForConstructorHeader
|
||||
|
||||
val newTowerDataContextForStaticNestedClasses =
|
||||
if ((owner as? FirRegularClass)?.classKind?.isSingleton == true)
|
||||
forMembersResolution
|
||||
@@ -437,6 +447,7 @@ class BodyResolveContext(
|
||||
newTowerDataContextForStaticNestedClasses,
|
||||
statics,
|
||||
scopeForConstructorHeader,
|
||||
scopeForEnumEntries,
|
||||
primaryConstructorPureParametersScope,
|
||||
primaryConstructorAllParametersScope
|
||||
)
|
||||
@@ -569,7 +580,7 @@ class BodyResolveContext(
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun <T> forEnumEntry(
|
||||
f: () -> T
|
||||
): T = withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER, f)
|
||||
): T = withTowerDataMode(FirTowerDataMode.ENUM_ENTRY, f)
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun <T> withAnonymousInitializer(
|
||||
|
||||
Reference in New Issue
Block a user