diff --git a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirBuiltinSymbolProvider.kt b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirBuiltinSymbolProvider.kt index ec03ff32768..631054e20f9 100644 --- a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirBuiltinSymbolProvider.kt +++ b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirBuiltinSymbolProvider.kt @@ -208,7 +208,7 @@ class FirBuiltinSymbolProvider(session: FirSession, val kotlinScopeProvider: Kot symbol = FirNamedFunctionSymbol( CallableId(packageFqName, relativeClassName, name), // set overriddenSymbol for "invoke" of KFunction/KSuspendFunction - superKind != null, superKind?.getInvoke(arity) + superKind?.getInvoke(arity) ) resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES valueParameters += typeArguments.dropLast(1).mapIndexed { index, typeArgument -> 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 e1fa98432ae..1c9c5670c5d 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 @@ -218,7 +218,7 @@ internal tailrec fun FirCallableSymbol<*>.deepestOverriddenSymbol(): FirCallable } internal tailrec fun FirCallableSymbol<*>.deepestMatchingOverriddenSymbol(root: FirCallableSymbol<*> = this): FirCallableSymbol<*> { - if (isIntersectionOverride) return this + if (fir.isIntersectionOverride) return this val overriddenSymbol = overriddenSymbol?.takeIf { it.containingClass() == root.containingClass() } ?: return this diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 598632f58b4..02894d64a17 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -1033,8 +1033,8 @@ class Fir2IrDeclarationStorage( val irFunction = firDeclaration.convertWithOffsets { startOffset, endOffset -> symbolTable.declareSimpleFunction(signature, { symbol }) { val isFakeOverride = - firFunctionSymbol is FirNamedFunctionSymbol && firFunctionSymbol.isFakeOverride && - firFunctionSymbol.callableId != firFunctionSymbol.overriddenSymbol?.callableId + firFunctionSymbol is FirNamedFunctionSymbol && firFunctionSymbol.fir.isSubstitutionOverride && + firFunctionSymbol.dispatchReceiverClassOrNull() != firFunctionSymbol.overriddenSymbol?.dispatchReceiverClassOrNull() Fir2IrLazySimpleFunction( components, startOffset, endOffset, parentOrigin, firDeclaration, irParent.fir, symbol, isFakeOverride ).apply { @@ -1065,7 +1065,7 @@ class Fir2IrDeclarationStorage( parentOrigin: IrDeclarationOrigin, irParent: IrDeclarationParent? ): IrDeclarationOrigin { - return if (irParent.isSourceClass() && symbol.isIntersectionOverride || (symbol.fir.origin as? PossiblyFirFakeOverrideSymbol<*, *>)?.isFakeOverride == true) + return if (irParent.isSourceClass() && symbol.fir.isIntersectionOverride) IrDeclarationOrigin.FAKE_OVERRIDE else parentOrigin @@ -1100,7 +1100,7 @@ class Fir2IrDeclarationStorage( val irProperty = fir.convertWithOffsets { startOffset, endOffset -> symbolTable.declareProperty(signature, { symbol }) { val isFakeOverride = - firPropertySymbol.isFakeOverride && + firPropertySymbol.fir.isSubstitutionOverride && firPropertySymbol.dispatchReceiverClassOrNull() != firPropertySymbol.overriddenSymbol?.dispatchReceiverClassOrNull() Fir2IrLazyProperty( components, startOffset, endOffset, declarationOrigin, fir, irParent.fir, symbol, isFakeOverride diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt index 380d9ff6582..f6b88285976 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt @@ -8,6 +8,8 @@ package org.jetbrains.kotlin.fir.backend.generators import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.isIntersectionOverride +import org.jetbrains.kotlin.fir.isSubstitutionOverride import org.jetbrains.kotlin.fir.scopes.* import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag @@ -100,7 +102,7 @@ internal class DelegatedMemberGenerator( val wrappedSymbol = wrapped.symbol as? S ?: return null return when { - wrappedSymbol.isFakeOverride && + wrappedSymbol.fir.isSubstitutionOverride && (wrappedSymbol.fir.dispatchReceiverType as? ConeClassLikeType)?.lookupTag == firSubClass.symbol.toLookupTag() -> wrapped.symbol.overriddenSymbol!!.fir else -> wrapped @@ -108,13 +110,13 @@ internal class DelegatedMemberGenerator( } private fun isJavaDefault(function: FirSimpleFunction): Boolean { - if (function.symbol.isIntersectionOverride) return isJavaDefault(function.symbol.overriddenSymbol!!.fir) + if (function.isIntersectionOverride) return isJavaDefault(function.symbol.overriddenSymbol!!.fir) return function.origin == FirDeclarationOrigin.Enhancement && function.modality == Modality.OPEN } private fun > S.unwrapIntersectionOverride(directOverridden: S.() -> List): S? { if (this !is PossiblyFirFakeOverrideSymbol<*, *>) return this - if (this.isIntersectionOverride) return directOverridden().firstOrNull { it.fir.delegatedWrapperData != null } + if (this.fir.isIntersectionOverride) return directOverridden().firstOrNull { it.fir.delegatedWrapperData != null } return this } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt index e40a2f1598d..ebba7822856 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.FirSymbolOwner import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.dispatchReceiverClassOrNull +import org.jetbrains.kotlin.fir.isSubstitutionOverride import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.defaultType import org.jetbrains.kotlin.fir.scopes.FirTypeScope @@ -157,9 +158,7 @@ class FakeOverrideGenerator( val origin = IrDeclarationOrigin.FAKE_OVERRIDE val baseSymbol = originalSymbol.deepestOverriddenSymbol() as S - if ((originalSymbol.isFakeOverride || originalSymbol.isIntersectionOverride) && - originalSymbol.dispatchReceiverClassOrNull() == classLookupTag - ) { + if (originalSymbol.fir.origin.fromSupertypes && originalSymbol.dispatchReceiverClassOrNull() == classLookupTag) { // Substitution case // NB: see comment above about substituted function' parent val irDeclaration = cachedIrDeclaration(originalDeclaration)?.takeIf { it.parent == irClass } @@ -201,10 +200,10 @@ class FakeOverrideGenerator( scope: FirTypeScope, containingClass: ConeClassLikeLookupTag, ): List { - if (!symbol.isIntersectionOverride) return listOf(basedSymbol) + if (symbol.fir.origin != FirDeclarationOrigin.IntersectionOverride) return listOf(basedSymbol) return scope.directOverridden(symbol).map { @Suppress("UNCHECKED_CAST") - if (it is PossiblyFirFakeOverrideSymbol<*, *> && it.isFakeOverride && it.dispatchReceiverClassOrNull() == containingClass) + if (it is PossiblyFirFakeOverrideSymbol<*, *> && it.fir.isSubstitutionOverride && it.dispatchReceiverClassOrNull() == containingClass) it.overriddenSymbol!! as S else it diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirImplicitBodyResolve.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirImplicitBodyResolve.kt index b867ab4833f..4c11b84978a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirImplicitBodyResolve.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirImplicitBodyResolve.kt @@ -211,13 +211,13 @@ private class ReturnTypeCalculatorWithJump( return tryCalculateReturnType(declaration.getter.delegate) } - if (declaration.origin == FirDeclarationOrigin.IntersectionOverride) { + if (declaration.isIntersectionOverride) { val result = tryCalculateReturnType(declaration.symbol.overriddenSymbol!!.fir) declaration.replaceReturnTypeRef(result) return result } - runIf(declaration.origin == FirDeclarationOrigin.SubstitutionOverride) { + runIf(declaration.isSubstitutionOverride) { val possiblyFirFakeOverrideSymbol = declaration.symbol as PossiblyFirFakeOverrideSymbol<*, *> val overriddenDeclaration = possiblyFirFakeOverrideSymbol.overriddenSymbol?.fir as FirTypedDeclaration? ?: return@runIf tryCalculateReturnType(overriddenDeclaration) 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 569ed070e76..cda5129b689 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 @@ -92,11 +92,11 @@ class FirDelegatedMemberScope( val delegatedSymbol = delegatedPropertyCache.getOrPut(propertySymbol) { FirFakeOverrideGenerator.createCopyForFirProperty( FirPropertySymbol( - propertySymbol.callableId, - overriddenSymbol = propertySymbol + propertySymbol.callableId ), original, session, + FirDeclarationOrigin.Delegated, newModality = Modality.OPEN, newDispatchReceiverType = dispatchReceiverType, ).apply { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt index d93efa966b4..45e1268f99e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/scopes/impl/FirFakeOverrideGenerator.kt @@ -43,7 +43,7 @@ object FirFakeOverrideGenerator { ): FirNamedFunctionSymbol { val symbol = FirNamedFunctionSymbol( CallableId(derivedClassId ?: baseSymbol.callableId.classId!!, baseFunction.name), - isFakeOverride = true, overriddenSymbol = baseSymbol + overriddenSymbol = baseSymbol ) createFakeOverrideFunction( symbol, session, baseFunction, newDispatchReceiverType, newReceiverType, newReturnType, @@ -250,10 +250,10 @@ object FirFakeOverrideGenerator { ): FirPropertySymbol { val symbol = FirPropertySymbol( CallableId(derivedClassId ?: baseSymbol.callableId.classId!!, baseProperty.name), - isFakeOverride = true, overriddenSymbol = baseSymbol + overriddenSymbol = baseSymbol ) createCopyForFirProperty( - symbol, baseProperty, session, isExpect, + symbol, baseProperty, session, FirDeclarationOrigin.SubstitutionOverride, isExpect, newDispatchReceiverType, newTypeParameters, newReceiverType, newReturnType, fakeOverrideSubstitution = fakeOverrideSubstitution ) @@ -264,6 +264,7 @@ object FirFakeOverrideGenerator { newSymbol: FirPropertySymbol, baseProperty: FirProperty, session: FirSession, + origin: FirDeclarationOrigin, isExpect: Boolean = baseProperty.isExpect, newDispatchReceiverType: ConeKotlinType?, newTypeParameters: List? = null, @@ -276,7 +277,7 @@ object FirFakeOverrideGenerator { return buildProperty { source = baseProperty.source this.session = session - origin = FirDeclarationOrigin.SubstitutionOverride + this.origin = origin name = baseProperty.name isVar = baseProperty.isVar this.symbol = newSymbol 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 5df2d932cc9..26871a7fa40 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 @@ -5,8 +5,10 @@ package org.jetbrains.kotlin.fir.scopes.impl -import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin +import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration +import org.jetbrains.kotlin.fir.isIntersectionOverride +import org.jetbrains.kotlin.fir.isSubstitutionOverride import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator import org.jetbrains.kotlin.fir.scopes.FirTypeScope @@ -73,7 +75,8 @@ class FirScopeWithFakeOverrideTypeCalculator( } private fun updateReturnType(declaration: FirTypedDeclaration) { - if (declaration.origin == FirDeclarationOrigin.SubstitutionOverride || declaration.origin == FirDeclarationOrigin.IntersectionOverride) { + if (declaration !is FirCallableMemberDeclaration<*>) return + if (declaration.isSubstitutionOverride || declaration.isIntersectionOverride) { fakeOverrideTypeCalculator.computeReturnType(declaration) } } 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 f2d8fc71c8a..4a98bbcc7f0 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 @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.fir.dispatchReceiverClassOrNull import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.scopes.* import org.jetbrains.kotlin.fir.symbols.CallableId -import org.jetbrains.kotlin.fir.symbols.PossiblyFirFakeOverrideSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.Name @@ -187,7 +186,7 @@ class FirTypeIntersectionScope private constructor( processDirectOverridden: FirTypeScope.(D, (D, FirTypeScope) -> ProcessorAction) -> ProcessorAction, ) { if (!visited.add(symbol)) return - if (!symbol.isIntersectionOverride && !(symbol as PossiblyFirFakeOverrideSymbol<*, *>).isFakeOverride) { + if (!symbol.fir.origin.fromSupertypes) { result.add(MemberWithBaseScope(symbol, scope)) return } @@ -265,9 +264,7 @@ class FirTypeIntersectionScope private constructor( dispatchReceiverType.classId ?: mostSpecific.dispatchReceiverClassOrNull()?.classId!!, mostSpecific.fir.name ), - mostSpecific.isFakeOverride, - mostSpecific, - isIntersectionOverride = true + mostSpecific ) val mostSpecificFunction = mostSpecific.fir FirFakeOverrideGenerator.createCopyForFirFunction( @@ -286,10 +283,10 @@ class FirTypeIntersectionScope private constructor( newModality: Modality, newVisibility: Visibility, ): FirPropertySymbol { - val newSymbol = FirPropertySymbol(mostSpecific.callableId, mostSpecific.isFakeOverride, mostSpecific, isIntersectionOverride = true) + val newSymbol = FirPropertySymbol(mostSpecific.callableId, mostSpecific) val mostSpecificProperty = mostSpecific.fir FirFakeOverrideGenerator.createCopyForFirProperty( - newSymbol, mostSpecificProperty, mostSpecificProperty.session, + newSymbol, mostSpecificProperty, mostSpecificProperty.session, FirDeclarationOrigin.IntersectionOverride, newModality = newModality, newVisibility = newVisibility, newDispatchReceiverType = dispatchReceiverType, diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt index fc727bdabc0..bbefe92fcca 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt @@ -5,10 +5,7 @@ package org.jetbrains.kotlin.fir -import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration -import org.jetbrains.kotlin.fir.declarations.FirCallableMemberDeclaration -import org.jetbrains.kotlin.fir.declarations.FirDeclarationDataKey -import org.jetbrains.kotlin.fir.declarations.FirDeclarationDataRegistry +import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.types.ConeClassLikeType @@ -19,7 +16,7 @@ fun FirCallableSymbol<*>.dispatchReceiverClassOrNull(): ConeClassLikeLookupTag? fun FirCallableDeclaration<*>.dispatchReceiverClassOrNull(): ConeClassLikeLookupTag? { if (this !is FirCallableMemberDeclaration<*>) return null - if (dispatchReceiverType is ConeIntersectionType && symbol.isIntersectionOverride) return symbol.overriddenSymbol!!.fir.dispatchReceiverClassOrNull() + if (dispatchReceiverType is ConeIntersectionType && isIntersectionOverride) return symbol.overriddenSymbol!!.fir.dispatchReceiverClassOrNull() return (dispatchReceiverType as? ConeClassLikeType)?.lookupTag } @@ -31,3 +28,7 @@ fun FirCallableDeclaration<*>.containingClass(): ConeClassLikeLookupTag? { private object ContainingClassKey : FirDeclarationDataKey() var FirCallableDeclaration<*>.containingClassAttr: ConeClassLikeLookupTag? by FirDeclarationDataRegistry.data(ContainingClassKey) + + +val FirCallableDeclaration<*>.isIntersectionOverride get() = origin == FirDeclarationOrigin.IntersectionOverride +val FirCallableDeclaration<*>.isSubstitutionOverride get() = origin == FirDeclarationOrigin.SubstitutionOverride diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt index 76595390c80..59eed1f2cd8 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/FirRenderer.kt @@ -973,14 +973,10 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM override fun visitResolvedNamedReference(resolvedNamedReference: FirResolvedNamedReference) { print("R|") val symbol = resolvedNamedReference.resolvedSymbol - val isFakeOverride = when (symbol) { - is FirNamedFunctionSymbol -> symbol.isFakeOverride - is FirPropertySymbol -> symbol.isFakeOverride - else -> false - } + val isSubstitutionOverride = (symbol.fir as? FirCallableMemberDeclaration)?.isSubstitutionOverride == true - if (isFakeOverride) { - print("FakeOverride<") + if (isSubstitutionOverride) { + print("SubstitutionOverride<") } print(symbol.unwrapIntersectionOverrides().render()) @@ -995,7 +991,7 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM } } - if (isFakeOverride) { + if (isSubstitutionOverride) { when (symbol) { is FirNamedFunctionSymbol -> { print(": ") @@ -1012,7 +1008,7 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM } private fun AbstractFirBasedSymbol<*>.unwrapIntersectionOverrides(): AbstractFirBasedSymbol<*> { - if (this is FirCallableSymbol<*> && isIntersectionOverride) return overriddenSymbol!!.unwrapIntersectionOverrides() + if (this is FirCallableSymbol<*> && fir.isIntersectionOverride) return overriddenSymbol!!.unwrapIntersectionOverrides() return this } 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 89c84c78e4c..34fdbb741d0 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 @@ -5,6 +5,7 @@ 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 @@ -69,7 +70,7 @@ abstract class FirTypeScope : FirScope(), FirContainingNamesAwareScope { ?: return baseScope.processDirectOverriddenCallables(callableSymbol, processor) for (overridden in directOverridden) { - if (overridden.isIntersectionOverride) { + if (overridden.fir.isIntersectionOverride) { if (!baseScope.processDirectOverriddenCallables(overridden, processor)) return ProcessorAction.STOP } if (!processor(overridden, baseScope)) return ProcessorAction.STOP diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/PossiblyFirFakeOverrideSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/PossiblyFirFakeOverrideSymbol.kt index 49a5c50a653..a3ba5c3e24d 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/PossiblyFirFakeOverrideSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/PossiblyFirFakeOverrideSymbol.kt @@ -9,7 +9,5 @@ import org.jetbrains.kotlin.fir.FirSymbolOwner import org.jetbrains.kotlin.fir.declarations.FirDeclaration interface PossiblyFirFakeOverrideSymbol> : FirBasedSymbol where E : FirSymbolOwner, E : FirDeclaration { - // contract isFakeOverride == true <=> overriddenSymbol != null - val isFakeOverride: Boolean val overriddenSymbol: S? -} \ No newline at end of file +} diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt index 0948332cfd9..48a5007468b 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirCallableSymbol.kt @@ -17,8 +17,6 @@ abstract class FirCallableSymbol> : AbstractFirBas open val overriddenSymbol: FirCallableSymbol? get() = null - - open val isIntersectionOverride: Boolean get() = false } val FirCallableSymbol<*>.isStatic: Boolean get() = (fir as? FirMemberDeclaration)?.status?.isStatic == true diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt index 857ed082c87..8c0f4b02b21 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirFunctionSymbol.kt @@ -24,10 +24,7 @@ sealed class FirFunctionSymbol>( open class FirNamedFunctionSymbol( callableId: CallableId, - override val isFakeOverride: Boolean = false, - // Actual for fake override only override val overriddenSymbol: FirNamedFunctionSymbol? = null, - override val isIntersectionOverride: Boolean = false, ) : FirFunctionSymbol(callableId), PossiblyFirFakeOverrideSymbol class FirConstructorSymbol( diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt index 2d776e76ebf..dad7f9157c8 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt @@ -23,10 +23,7 @@ open class FirVariableSymbol>(override val callableId: Callab open class FirPropertySymbol( callableId: CallableId, - override val isFakeOverride: Boolean = false, - // Actual for fake override only override val overriddenSymbol: FirPropertySymbol? = null, - override val isIntersectionOverride: Boolean = false, ) : FirVariableSymbol(callableId), PossiblyFirFakeOverrideSymbol { // TODO: should we use this constructor for local variables? constructor(name: Name) : this(CallableId(name)) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/fir/FirUtils.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/fir/FirUtils.kt index f1037464305..1ae211a5569 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/fir/FirUtils.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/fir/FirUtils.kt @@ -6,10 +6,12 @@ package org.jetbrains.kotlin.idea.fir import org.jetbrains.kotlin.fir.FirSymbolOwner +import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirDeclaration -import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.expressions.FirFunctionCall import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression +import org.jetbrains.kotlin.fir.isIntersectionOverride +import org.jetbrains.kotlin.fir.isSubstitutionOverride import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol @@ -50,6 +52,6 @@ internal inline fun D.unrollFakeOverrides(): D where D : FirDeclarat private inline val FirBasedSymbol<*>.isFakeOrIntersectionOverride: Boolean get() { - val origin = (fir as? FirDeclaration)?.origin ?: return false - return origin == FirDeclarationOrigin.SubstitutionOverride || origin == FirDeclarationOrigin.IntersectionOverride + val declaration = fir as? FirCallableDeclaration<*> ?: return false + return declaration.isSubstitutionOverride || declaration.isIntersectionOverride } diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/scopes/KtFirDelegatingScope.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/scopes/KtFirDelegatingScope.kt index 10e0e1a6005..5d92572bd84 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/scopes/KtFirDelegatingScope.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/scopes/KtFirDelegatingScope.kt @@ -5,7 +5,8 @@ package org.jetbrains.kotlin.idea.frontend.api.fir.scopes -import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction +import org.jetbrains.kotlin.fir.isSubstitutionOverride import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope import org.jetbrains.kotlin.fir.scopes.FirScope import org.jetbrains.kotlin.fir.scopes.processClassifiersByName @@ -65,7 +66,7 @@ internal fun FirScope.getCallableSymbols(callableNames: Collection, builde } processPropertiesByName(name) { firSymbol -> val symbol = when { - firSymbol is FirPropertySymbol && firSymbol.isFakeOverride -> { + firSymbol is FirPropertySymbol && firSymbol.fir.isSubstitutionOverride -> { builder.buildVariableSymbol(firSymbol.fir) } else -> builder.buildCallableSymbol(firSymbol.fir) @@ -85,4 +86,4 @@ internal fun FirScope.getClassifierSymbols(classLikeNames: Collection, bui } yieldAll(classifierSymbols) } - } \ No newline at end of file + } diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenMemberGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenMemberGenerator.kt index d4bdd0059d8..2dae57e0115 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenMemberGenerator.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenMemberGenerator.kt @@ -46,7 +46,7 @@ class AllOpenMemberGenerator(session: FirSession) : FirDeclarationGenerationExte returnTypeRef = annotatedDeclaration.returnTypeRef status = annotatedDeclaration.status name = Name.identifier("hello${propertyName.capitalize()}") - symbol = FirNamedFunctionSymbol(CallableId(owner.classId, name), isFakeOverride = false) + symbol = FirNamedFunctionSymbol(CallableId(owner.classId, name)) } return listOf(GeneratedDeclaration(function, owner)) } @@ -55,4 +55,4 @@ class AllOpenMemberGenerator(session: FirSession) : FirDeclarationGenerationExte override val key: FirPluginKey get() = AllOpenPluginKey -} \ No newline at end of file +} diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenNestedClassGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenNestedClassGenerator.kt index 68bb29076d9..3bac27e971c 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenNestedClassGenerator.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenNestedClassGenerator.kt @@ -81,7 +81,7 @@ class AllOpenNestedClassGenerator(session: FirSession) : FirDeclarationGeneratio Modality.FINAL ) name = Name.identifier("hello") - symbol = FirNamedFunctionSymbol(CallableId(classId, name), isFakeOverride = false) + symbol = FirNamedFunctionSymbol(CallableId(classId, name)) } return listOf(constructor, function) } diff --git a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenTopLevelDeclarationsGenerator.kt b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenTopLevelDeclarationsGenerator.kt index abb5816c428..37660925645 100644 --- a/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenTopLevelDeclarationsGenerator.kt +++ b/plugins/fir/fir-plugin-prototype/src/org/jetbrains/kotlin/fir/plugin/generators/AllOpenTopLevelDeclarationsGenerator.kt @@ -59,7 +59,7 @@ class AllOpenTopLevelDeclarationsGenerator(session: FirSession) : FirDeclaration Modality.FINAL ) name = Name.identifier("hello") - symbol = FirNamedFunctionSymbol(CallableId(klass.symbol.classId, name), isFakeOverride = false) + symbol = FirNamedFunctionSymbol(CallableId(klass.symbol.classId, name)) } return listOf(function) }