From 15021f30ff295553b8b19b616f8c2a3741bcb7ad Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 2 Dec 2020 17:22:18 +0300 Subject: [PATCH] Use FirNamedFunctionSymbol around processOverriddenFunctions --- .../fir/analysis/checkers/FirHelpers.kt | 4 +- .../kotlin/fir/backend/ConversionUtils.kt | 42 ++++++++++--------- .../JavaAnnotationSyntheticPropertiesScope.kt | 4 +- .../JavaClassMembersEnhancementScope.kt | 21 ++++------ .../kotlin/fir/scopes/jvm/JvmMappedScope.kt | 4 +- .../org/jetbrains/kotlin/fir/SessionUtils.kt | 13 ++---- .../resolve/FirDefaultParametersResolver.kt | 4 +- .../kotlin/fir/resolve/calls/Synthetics.kt | 5 ++- .../fir/resolve/inference/InferenceUtils.kt | 7 +++- .../resolve/transformers/FirStatusResolver.kt | 13 +++--- .../impl/AbstractFirUseSiteMemberScope.kt | 24 +++++------ .../scopes/impl/FirClassSubstitutionScope.kt | 4 +- .../scopes/impl/FirDelegatedMemberScope.kt | 4 +- .../FirScopeWithFakeOverrideTypeCalculator.kt | 4 +- .../scopes/impl/FirTypeIntersectionScope.kt | 4 +- .../jetbrains/kotlin/fir/scopes/FirScope.kt | 21 +++++----- .../kotlin/fir/scopes/FirTypeScope.kt | 18 ++++---- 17 files changed, 97 insertions(+), 99 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index b214513dce0..a0023cc3134 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.ConeKotlinType @@ -152,7 +153,7 @@ fun FirSymbolOwner<*>.getContainingClass(context: CheckerContext): FirClassLikeD * Returns the FirClassLikeDeclaration the type alias is pointing * to provided `this` is a FirTypeAlias. Returns this otherwise. */ -fun FirClassLikeDeclaration<*>.followAlias(session: FirSession): FirClassLikeDeclaration<*>? { +fun FirClassLikeDeclaration<*>.followAlias(session: FirSession): FirClassLikeDeclaration<*> { return this.safeAs() ?.expandedTypeRef ?.firClassLike(session) @@ -199,6 +200,7 @@ fun FirSimpleFunction.overriddenFunctions( containingClass: FirClass<*>, context: CheckerContext ): List> { + val symbol = symbol as? FirNamedFunctionSymbol ?: return emptyList() val firTypeScope = containingClass.unsubstitutedScope( context.sessionHolder.session, context.sessionHolder.scopeSession, diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt index 908b8a7c018..6d3a9201a61 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt @@ -140,26 +140,27 @@ fun FirReference.toSymbolForCall( } } -private fun FirCallableSymbol<*>.toSymbolForCall(declarationStorage: Fir2IrDeclarationStorage, preferGetter: Boolean): IrSymbol? = when (this) { - is FirFunctionSymbol<*> -> declarationStorage.getIrFunctionSymbol(this) - is SyntheticPropertySymbol -> { - (fir as? FirSyntheticProperty)?.let { syntheticProperty -> - val delegateSymbol = if (preferGetter) { - syntheticProperty.getter.delegate.symbol - } else { - syntheticProperty.setter?.delegate?.symbol - ?: throw AssertionError("Written synthetic property must have a setter") - } - delegateSymbol.unwrapCallRepresentative().toSymbolForCall(declarationStorage, preferGetter) - } ?: declarationStorage.getIrPropertySymbol(this) +private fun FirCallableSymbol<*>.toSymbolForCall(declarationStorage: Fir2IrDeclarationStorage, preferGetter: Boolean): IrSymbol? = + when (this) { + is FirFunctionSymbol<*> -> declarationStorage.getIrFunctionSymbol(this) + is SyntheticPropertySymbol -> { + (fir as? FirSyntheticProperty)?.let { syntheticProperty -> + val delegateSymbol = if (preferGetter) { + syntheticProperty.getter.delegate.symbol + } else { + syntheticProperty.setter?.delegate?.symbol + ?: throw AssertionError("Written synthetic property must have a setter") + } + delegateSymbol.unwrapCallRepresentative().toSymbolForCall(declarationStorage, preferGetter) + } ?: declarationStorage.getIrPropertySymbol(this) + } + is FirPropertySymbol -> declarationStorage.getIrPropertySymbol(this) + is FirFieldSymbol -> declarationStorage.getIrFieldSymbol(this) + is FirBackingFieldSymbol -> declarationStorage.getIrBackingFieldSymbol(this) + is FirDelegateFieldSymbol<*> -> declarationStorage.getIrBackingFieldSymbol(this) + is FirVariableSymbol<*> -> declarationStorage.getIrValueSymbol(this) + else -> null } - is FirPropertySymbol -> declarationStorage.getIrPropertySymbol(this) - is FirFieldSymbol -> declarationStorage.getIrFieldSymbol(this) - is FirBackingFieldSymbol -> declarationStorage.getIrBackingFieldSymbol(this) - is FirDelegateFieldSymbol<*> -> declarationStorage.getIrBackingFieldSymbol(this) - is FirVariableSymbol<*> -> declarationStorage.getIrValueSymbol(this) - else -> null -} fun FirConstExpression<*>.getIrConstKind(): IrConstKind<*> = when (kind) { FirConstKind.IntegerLiteral -> { @@ -249,8 +250,9 @@ internal fun FirSimpleFunction.generateOverriddenFunctionSymbols( val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true) scope.processFunctionsByName(name) {} val overriddenSet = mutableSetOf() + val symbol = symbol as? FirNamedFunctionSymbol ?: return emptyList() scope.processDirectlyOverriddenFunctions(symbol) { - if ((it.fir as FirSimpleFunction).visibility == Visibilities.Private) { + if (it.fir.visibility == Visibilities.Private) { return@processDirectlyOverriddenFunctions ProcessorAction.NEXT } diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt index 35adabf64c1..1728ddcd160 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaAnnotationSyntheticPropertiesScope.kt @@ -55,8 +55,8 @@ class JavaAnnotationSyntheticPropertiesScope( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction { return ProcessorAction.NONE } diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassMembersEnhancementScope.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassMembersEnhancementScope.kt index f66b0687f45..c7341de513d 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassMembersEnhancementScope.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaClassMembersEnhancementScope.kt @@ -36,7 +36,7 @@ class JavaClassMembersEnhancementScope( private val owner: FirRegularClassSymbol, private val useSiteMemberScope: JavaClassUseSiteMemberScope, ) : FirTypeScope() { - private val overriddenFunctions = mutableMapOf, Collection>>() + private val overriddenFunctions = mutableMapOf>() private val overriddenProperties = mutableMapOf>() private val overrideBindCache = mutableMapOf?, List>>>() @@ -149,16 +149,11 @@ class JavaClassMembersEnhancementScope( val enhancedFunction = (symbol.fir as? FirSimpleFunction)?.changeSignatureIfErasedValueParameter() val enhancedFunctionSymbol = enhancedFunction?.symbol ?: symbol - val originalFunction = original.fir as? FirSimpleFunction - - overriddenFunctions[enhancedFunctionSymbol] = - if (enhancedFunction != null && originalFunction != null) - originalFunction - .overriddenMembers(enhancedFunction.name) - .mapNotNull { it.symbol as? FirFunctionSymbol<*> } - else - emptyList() - + if (enhancedFunctionSymbol is FirNamedFunctionSymbol && original is FirNamedFunctionSymbol) { + overriddenFunctions[enhancedFunctionSymbol] = original.fir + .overriddenMembers(enhancedFunctionSymbol.fir.name) + .mapNotNull { it.symbol as? FirNamedFunctionSymbol } + } processor(enhancedFunctionSymbol) } @@ -188,8 +183,8 @@ class JavaClassMembersEnhancementScope( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction = doProcessDirectOverriddenCallables( functionSymbol, processor, overriddenFunctions, useSiteMemberScope, diff --git a/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt b/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt index b0764383e8b..141be33094d 100644 --- a/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt +++ b/compiler/fir/jvm/src/org/jetbrains/kotlin/fir/scopes/jvm/JvmMappedScope.kt @@ -42,8 +42,8 @@ class JvmMappedScope( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ) = ProcessorAction.NONE override fun processDeclaredConstructors(processor: (FirConstructorSymbol) -> Unit) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/SessionUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/SessionUtils.kt index fd31dc34384..050a43bf830 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/SessionUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/SessionUtils.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope +import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.types.ConeInferenceContext import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext @@ -29,6 +30,7 @@ fun FirSimpleFunction.lowestVisibilityAmongOverrides( session: FirSession, scopeSession: ScopeSession ): Visibility { + val symbol = symbol as? FirNamedFunctionSymbol ?: return visibility val firTypeScope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false) var visibility = visibility @@ -37,16 +39,7 @@ fun FirSimpleFunction.lowestVisibilityAmongOverrides( firTypeScope.processFunctionsByName(symbol.fir.name) { } firTypeScope.processOverriddenFunctions(symbol) { - val overriddenVisibility = when (val fir = it.fir) { - is FirMemberDeclaration -> fir.visibility - is FirPropertyAccessor -> fir.visibility - else -> null - } - - overriddenVisibility?.let { that -> - visibility = that - } - + visibility = it.fir.visibility ProcessorAction.NEXT } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirDefaultParametersResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirDefaultParametersResolver.kt index 78c76cfe569..bc4ae62c53f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirDefaultParametersResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/FirDefaultParametersResolver.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.scopes.FirTypeScope import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.processOverriddenFunctions +import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol class FirDefaultParametersResolver : FirSessionComponent { fun declaresDefaultValue( @@ -23,9 +24,10 @@ class FirDefaultParametersResolver : FirSessionComponent { ): Boolean { if (valueParameter.defaultValue != null) return true if (originScope !is FirTypeScope) return false + val symbol = function.symbol as? FirNamedFunctionSymbol ?: return false var result = false - originScope.processOverriddenFunctions(function.symbol) { overridden -> + originScope.processOverriddenFunctions(symbol) { overridden -> if (overridden.fir.valueParameters[index].defaultValue != null) { result = true return@processOverriddenFunctions ProcessorAction.STOP diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt index 99afcf68f14..604d216b827 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Synthetics.kt @@ -56,7 +56,8 @@ class FirSyntheticPropertiesScope( getterSymbol: FirFunctionSymbol<*>, processor: (FirVariableSymbol<*>) -> Unit ) { - val getter = getterSymbol.fir as? FirSimpleFunction ?: return + if (getterSymbol !is FirNamedFunctionSymbol) return + val getter = getterSymbol.fir if (getter.typeParameters.isNotEmpty()) return if (getter.valueParameters.isNotEmpty()) return @@ -121,7 +122,7 @@ class FirSyntheticPropertiesScope( processor(property.symbol) } - private fun FirFunctionSymbol<*>.hasJavaOverridden(): Boolean { + private fun FirNamedFunctionSymbol.hasJavaOverridden(): Boolean { var result = false baseScope.processOverriddenFunctionsAndSelf(this) { if (it.unwrapFakeOverrides().fir.origin == FirDeclarationOrigin.Enhancement) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt index dc9e4f15eda..0ebce74b100 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceUtils.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope import org.jetbrains.kotlin.fir.symbols.StandardClassIds import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.typeContext import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl @@ -125,9 +126,11 @@ fun ConeKotlinType.findContributedInvokeSymbol( FakeOverrideTypeCalculator.DoNothing } val scope = scope(session, scopeSession, fakeOverrideTypeCalculator) ?: return null - var declaredInvoke: FirFunctionSymbol<*>? = null + var declaredInvoke: FirNamedFunctionSymbol? = null scope.processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol -> - if (functionSymbol.fir.valueParameters.size == baseInvokeSymbol.fir.valueParameters.size) { + if (functionSymbol is FirNamedFunctionSymbol && + functionSymbol.fir.valueParameters.size == baseInvokeSymbol.fir.valueParameters.size + ) { declaredInvoke = functionSymbol return@processFunctionsByName } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt index 28313a5819f..e6ec933f3bd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirStatusResolver.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.scopes.ProcessorAction import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope +import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol class FirStatusResolver( val session: FirSession, @@ -73,14 +74,14 @@ class FirStatusResolver( @Suppress("RemoveExplicitTypeArguments") // Workaround for KT-42175 buildList> { val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false) - scope.processFunctionsByName(function.name) {} - scope - .processDirectOverriddenFunctionsWithBaseScope(function.symbol) { symbol, _ -> - (symbol.fir as? FirCallableMemberDeclaration<*>)?.let { - this += it - } + val symbol = function.symbol + if (symbol is FirNamedFunctionSymbol) { + scope.processFunctionsByName(function.name) {} + scope.processDirectOverriddenFunctionsWithBaseScope(symbol) { overriddenSymbol, _ -> + this += overriddenSymbol.fir ProcessorAction.NEXT } + } }.mapNotNull { it.status as? FirResolvedDeclarationStatus } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt index 3b66f5868ae..b60a7d1a39d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/AbstractFirUseSiteMemberScope.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.fir.scopes.impl import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.scopes.* import org.jetbrains.kotlin.fir.symbols.impl.* @@ -20,7 +19,7 @@ abstract class AbstractFirUseSiteMemberScope( ) : AbstractFirOverrideScope(session, overrideChecker) { private val functions = hashMapOf>>() - private val directOverriddenFunctions = hashMapOf, Collection>>() + private val directOverriddenFunctions = hashMapOf>() protected val directOverriddenProperties = hashMapOf>() override fun processFunctionsByName(name: Name, processor: (FirFunctionSymbol<*>) -> Unit) { @@ -37,8 +36,10 @@ abstract class AbstractFirUseSiteMemberScope( val overrideCandidates = mutableSetOf>() declaredMemberScope.processFunctionsByName(name) { symbol -> if (symbol.isStatic) return@processFunctionsByName - val directOverridden = computeDirectOverridden(symbol) - this@AbstractFirUseSiteMemberScope.directOverriddenFunctions[symbol] = directOverridden + if (symbol is FirNamedFunctionSymbol) { + val directOverridden = computeDirectOverridden(symbol) + this@AbstractFirUseSiteMemberScope.directOverriddenFunctions[symbol] = directOverridden + } overrideCandidates += symbol add(symbol) } @@ -53,13 +54,12 @@ abstract class AbstractFirUseSiteMemberScope( } } - private fun computeDirectOverridden(symbol: FirFunctionSymbol<*>): Collection> { - val result = mutableListOf>() - val firSimpleFunction = symbol.fir as? FirSimpleFunction ?: return emptyList() + private fun computeDirectOverridden(symbol: FirNamedFunctionSymbol): Collection { + val result = mutableListOf() + val firSimpleFunction = symbol.fir superTypesScope.processFunctionsByName(symbol.callableId.callableName) { superSymbol -> - val superFunctionFir = superSymbol.fir - if (superFunctionFir is FirSimpleFunction && - overrideChecker.isOverriddenFunction(firSimpleFunction, superFunctionFir) + if (superSymbol is FirNamedFunctionSymbol && + overrideChecker.isOverriddenFunction(firSimpleFunction, superSymbol.fir) ) { result.add(superSymbol) } @@ -69,8 +69,8 @@ abstract class AbstractFirUseSiteMemberScope( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction = doProcessDirectOverriddenCallables( functionSymbol, processor, directOverriddenFunctions, superTypesScope, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt index 808ddf6985e..c62711f7d2f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt @@ -44,8 +44,8 @@ class FirClassSubstitutionScope( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction = processDirectOverriddenWithBaseScope( functionSymbol, processor, FirTypeScope::processDirectOverriddenFunctionsWithBaseScope, substitutionOverrideFunctions diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt index cda5129b689..3e20196a1d2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt @@ -108,8 +108,8 @@ class FirDelegatedMemberScope( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction { return processDirectOverriddenWithBaseScope( functionSymbol, processor, FirTypeScope::processDirectOverriddenFunctionsWithBaseScope diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt index 26871a7fa40..cf9466297d9 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt @@ -47,8 +47,8 @@ class FirScopeWithFakeOverrideTypeCalculator( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction { return delegate.processDirectOverriddenFunctionsWithBaseScope(functionSymbol) { symbol, scope -> updateReturnType(symbol.fir) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt index ed44c7157cc..64498314fc6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirTypeIntersectionScope.kt @@ -444,8 +444,8 @@ class FirTypeIntersectionScope private constructor( } override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction = processDirectOverriddenCallablesWithBaseScope( functionSymbol, processor, diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt index 6cb30557051..3345ec25923 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirScope.kt @@ -6,31 +6,32 @@ package org.jetbrains.kotlin.fir.scopes import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor -import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol +import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.name.Name abstract class FirScope { open fun processClassifiersByNameWithSubstitution( name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit - ) {} + ) { + } open fun processFunctionsByName( name: Name, processor: (FirFunctionSymbol<*>) -> Unit - ) {} + ) { + } open fun processPropertiesByName( name: Name, processor: (FirVariableSymbol<*>) -> Unit - ) {} + ) { + } open fun processDeclaredConstructors( processor: (FirConstructorSymbol) -> Unit - ) {} + ) { + } open fun mayContainName(name: Name) = true } @@ -52,8 +53,8 @@ fun FirScope.getDeclaredConstructors(): List = mutableList } fun FirTypeScope.processOverriddenFunctionsAndSelf( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol) -> ProcessorAction ): ProcessorAction { if (!processor(functionSymbol)) return ProcessorAction.STOP diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt index 34fdbb741d0..a1b542042fc 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.fir.scopes import org.jetbrains.kotlin.fir.isIntersectionOverride import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.name.Name @@ -29,8 +28,8 @@ abstract class FirTypeScope : FirScope(), FirContainingNamesAwareScope { // - It may silently do nothing on symbols originated from different scope instance // - It may return the same overridden symbols more then once in case of substitution abstract fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction // ------------------------------------------------------------------------------------ @@ -44,8 +43,8 @@ abstract class FirTypeScope : FirScope(), FirContainingNamesAwareScope { object Empty : FirTypeScope() { override fun processDirectOverriddenFunctionsWithBaseScope( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>, FirTypeScope) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction = ProcessorAction.NEXT override fun processDirectOverriddenPropertiesWithBaseScope( @@ -84,8 +83,8 @@ abstract class FirTypeScope : FirScope(), FirContainingNamesAwareScope { typealias ProcessOverriddenWithBaseScope = FirTypeScope.(D, (D, FirTypeScope) -> ProcessorAction) -> ProcessorAction fun FirTypeScope.processOverriddenFunctions( - functionSymbol: FirFunctionSymbol<*>, - processor: (FirFunctionSymbol<*>) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + processor: (FirNamedFunctionSymbol) -> ProcessorAction ): ProcessorAction = doProcessAllOverriddenCallables( functionSymbol, @@ -128,8 +127,8 @@ private fun > FirTypeScope.doProcessAllOverriddenCallab doProcessAllOverriddenCallables(callableSymbol, { s, _ -> processor(s) }, processDirectOverriddenCallablesWithBaseScope, visited) inline fun FirTypeScope.processDirectlyOverriddenFunctions( - functionSymbol: FirFunctionSymbol<*>, - crossinline processor: (FirFunctionSymbol<*>) -> ProcessorAction + functionSymbol: FirNamedFunctionSymbol, + crossinline processor: (FirNamedFunctionSymbol) -> ProcessorAction ): ProcessorAction = processDirectOverriddenFunctionsWithBaseScope(functionSymbol) { overridden, _ -> processor(overridden) } @@ -145,7 +144,6 @@ fun FirTypeScope.getDirectOverriddenFunctions(function: FirNamedFunctionSymbol): val overriddenFunctions = mutableSetOf() processDirectlyOverriddenFunctions(function) { - if (it !is FirNamedFunctionSymbol) return@processDirectlyOverriddenFunctions ProcessorAction.NEXT overriddenFunctions.add(it) ProcessorAction.NEXT }