[FIR] pre-resolve some scope callables before creating a scope

In a lot of cases, when we want to process the
declaration in scope, it should be resolved to at least TYPES phase.

To avoid doing it manually in all our variety of scopes, we do it when the scope it created.
It was implicitly working manually before as lazy resolve did a lot of extra work
on resolving a declaration it was not supposed to resolve.
Now it's not the case, and we have to explicitly resolve all the declarations we need.

^KT-56543

Co-authored-by: Ilya Kirillov <ilya.kirillov@jetbrains.com>
This commit is contained in:
Dmitrii Gridin
2023-03-22 13:01:27 +01:00
committed by Space Team
parent 23e40693a3
commit 706ff6b61f
46 changed files with 347 additions and 174 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -31,9 +31,8 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.resolver.AllCandidatesRes
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirEntry
import org.jetbrains.kotlin.analysis.utils.errors.ExceptionAttachmentBuilder
import org.jetbrains.kotlin.analysis.utils.errors.buildErrorWithAttachment
import org.jetbrains.kotlin.analysis.utils.errors.withPsiEntry
import org.jetbrains.kotlin.analysis.utils.errors.rethrowExceptionWithDetails
import org.jetbrains.kotlin.analysis.utils.errors.withPsiEntry
import org.jetbrains.kotlin.analysis.utils.printer.parentOfType
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
@@ -191,7 +190,10 @@ internal class KtFirCallResolver(
}
}
fun <T> transformErrorReference(call: FirElement, calleeReference: T): KtCallInfo where T : FirNamedReference, T : FirDiagnosticHolder {
fun <T> transformErrorReference(
call: FirElement,
calleeReference: T,
): KtCallInfo where T : FirNamedReference, T : FirDiagnosticHolder {
val diagnostic = calleeReference.diagnostic
val ktDiagnostic = calleeReference.createKtDiagnostic(psi)
@@ -953,7 +955,8 @@ internal class KtFirCallResolver(
return classSymbol.unsubstitutedScope(
analysisSession.useSiteSession,
analysisSession.getScopeSessionFor(analysisSession.useSiteSession),
withForcedTypeCalculator = true
withForcedTypeCalculator = true,
memberRequiredPhase = null,
)
.getConstructors(analysisSession.firSymbolBuilder)
.toList()
@@ -1193,8 +1196,10 @@ internal class KtFirCallResolver(
val scope = unsubstitutedScope(
analysisSession.useSiteSession,
analysisSession.getScopeSessionFor(analysisSession.useSiteSession),
false
false,
memberRequiredPhase = null,
)
var equalsSymbol: FirNamedFunctionSymbol? = null
scope.processFunctionsByName(EQUALS) { equalsSymbolFromScope ->
if (equalsSymbol != null) return@processFunctionsByName
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -89,7 +89,8 @@ internal class KtFirScopeProvider(
fir.unsubstitutedScope(
firSession,
getScopeSession(),
withForcedTypeCalculator = false
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
}?.applyIf(classSymbol is KtEnumEntrySymbol, ::EnumEntryContainingNamesAwareScope)
?: return getEmptyScope()
@@ -269,16 +270,26 @@ internal class KtFirScopeProvider(
)
}
private fun buildJavaEnhancementDeclaredMemberScope(useSiteSession: FirSession, symbol: FirRegularClassSymbol, scopeSession: ScopeSession): JavaClassDeclaredMembersEnhancementScope {
private fun buildJavaEnhancementDeclaredMemberScope(
useSiteSession: FirSession,
symbol: FirRegularClassSymbol,
scopeSession: ScopeSession,
): JavaClassDeclaredMembersEnhancementScope {
return scopeSession.getOrBuild(symbol, JAVA_ENHANCEMENT_FOR_DECLARED_MEMBER) {
val firJavaClass = symbol.fir
require(firJavaClass is FirJavaClass) {
"${firJavaClass.classId} is expected to be FirJavaClass, but ${firJavaClass::class} found"
}
JavaClassDeclaredMembersEnhancementScope(
useSiteSession,
firJavaClass,
JavaScopeProvider.getUseSiteMemberScope(firJavaClass, useSiteSession, scopeSession)
JavaScopeProvider.getUseSiteMemberScope(
firJavaClass,
useSiteSession,
scopeSession,
memberRequiredPhase = FirResolvePhase.TYPES,
)
)
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -11,20 +11,20 @@ import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirAnonymousObjectSymbol
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirBackingFieldSymbol
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirSymbol
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbolOrigin
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes
import org.jetbrains.kotlin.fir.scopes.*
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirIntersectionOverrideFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirIntersectionOverridePropertySymbol
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.types.toRegularClassSymbol
internal class KtFirSymbolDeclarationOverridesProvider(
@@ -120,8 +120,10 @@ internal class KtFirSymbolDeclarationOverridesProvider(
val firTypeScope = firContainer.unsubstitutedScope(
firSession,
analysisSession.getScopeSessionFor(firSession),
withForcedTypeCalculator = false
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
firTypeScope.processCallableByName(firCallableDeclaration)
process(firTypeScope, firCallableDeclaration)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -51,6 +51,7 @@ internal abstract class KtFirMemberSymbolPointer<S : KtSymbol>(
useSiteSession = firSession,
scopeSession = scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.builder.RawFirBuilder
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
@@ -53,7 +54,12 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
private fun receiverTypeMatch(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
if ((fir.receiverParameter != null) != (psi.receiverTypeReference != null)) return false
if (fir.receiverParameter != null && !isTheSameTypes(psi.receiverTypeReference!!, fir.receiverParameter!!.typeRef, isVararg = false)) {
if (fir.receiverParameter != null && !isTheSameTypes(
psi.receiverTypeReference!!,
fir.receiverParameter!!.typeRef,
isVararg = false,
)
) {
return false
}
return true
@@ -249,27 +255,25 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
}
private object DummyScopeProvider : FirScopeProvider() {
override fun getUseSiteMemberScope(klass: FirClass, useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope {
shouldNotBeCalled()
}
override fun getUseSiteMemberScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope = shouldNotBeCalled()
override fun getStaticMemberScopeForCallables(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirContainingNamesAwareScope? {
shouldNotBeCalled()
}
): FirContainingNamesAwareScope? = shouldNotBeCalled()
override fun getNestedClassifierScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirContainingNamesAwareScope? {
shouldNotBeCalled()
}
): FirContainingNamesAwareScope? = shouldNotBeCalled()
private fun shouldNotBeCalled(): Nothing =
error("Should not be called in RawFirBuilder while converting KtTypeReference")
private fun shouldNotBeCalled(): Nothing = error("Should not be called in RawFirBuilder while converting KtTypeReference")
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -46,7 +46,6 @@ abstract class AbstractPartialRawFirBuilderTestCase : AbstractLowLevelApiSingleF
}
}
private fun testFunctionPartialBuilding(ktFile: KtFile, nameToFind: String) {
testPartialBuilding(
ktFile
@@ -97,18 +96,24 @@ abstract class AbstractPartialRawFirBuilderTestCase : AbstractLowLevelApiSingleF
val elementToBuild = findPsiElement(file) as KtDeclaration
val scopeProvider = object : FirScopeProvider() {
override fun getUseSiteMemberScope(klass: FirClass, useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope =
error("Should not be called")
override fun getUseSiteMemberScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope = error("Should not be called")
override fun getStaticMemberScopeForCallables(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirContainingNamesAwareScope? =
error("Should not be called")
scopeSession: ScopeSession,
): FirContainingNamesAwareScope? = error("Should not be called")
override fun getNestedClassifierScope(klass: FirClass, useSiteSession: FirSession, scopeSession: ScopeSession): FirContainingNamesAwareScope? =
error("Should not be called")
override fun getNestedClassifierScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession,
): FirContainingNamesAwareScope? = error("Should not be called")
}
val session = FirSessionFactoryHelper.createEmptySession()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
@OptIn(SymbolInternals::class)
fun renderJavaClass(renderer: FirRenderer, javaClass: FirJavaClass, session: FirSession, renderInnerClasses: () -> Unit) {
val memberScope = javaClass.unsubstitutedScope(session, ScopeSession(), withForcedTypeCalculator = true)
val memberScope = javaClass.unsubstitutedScope(session, ScopeSession(), withForcedTypeCalculator = true, memberRequiredPhase = null)
val staticScope = javaClass.scopeProvider.getStaticScope(javaClass, session, ScopeSession())
@@ -51,7 +51,7 @@ object FirJsMultipleInheritanceChecker : FirClassChecker() {
val overridesWithSameName = scope.getFunctions(functionToCheck)
for (function in overridesWithSameName) {
val overridden = function.overriddenFunctions(symbol, context)
val overridden = function.overriddenFunctions(symbol, context, memberRequiredPhase = null)
if (
overridden.size > 1 &&
@@ -62,7 +62,7 @@ object FirJvmInconsistentOperatorFromJavaCallChecker : FirFunctionCallChecker()
// Check explicitly overridden contains
val containingClass = containingClassLookupTag()?.toFirRegularClassSymbol(context.session) ?: return false
val overriddenFunctions = overriddenFunctions(containingClass, context)
val overriddenFunctions = overriddenFunctions(containingClass, context, memberRequiredPhase = null)
for (overriddenFunction in overriddenFunctions) {
if (overriddenFunction is FirNamedFunctionSymbol && overriddenFunction.check(source, context, reporter)) {
return true
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -48,10 +48,20 @@ import org.jetbrains.kotlin.util.getChildren
private val INLINE_ONLY_ANNOTATION_CLASS_ID: ClassId = ClassId.topLevel(FqName("kotlin.internal.InlineOnly"))
fun FirClass.unsubstitutedScope(context: CheckerContext): FirTypeScope =
this.unsubstitutedScope(context.sessionHolder.session, context.sessionHolder.scopeSession, withForcedTypeCalculator = false)
this.unsubstitutedScope(
context.sessionHolder.session,
context.sessionHolder.scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
fun FirClassSymbol<*>.unsubstitutedScope(context: CheckerContext): FirTypeScope =
this.unsubstitutedScope(context.sessionHolder.session, context.sessionHolder.scopeSession, withForcedTypeCalculator = false)
this.unsubstitutedScope(
context.sessionHolder.session,
context.sessionHolder.scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
fun FirTypeRef.toClassLikeSymbol(session: FirSession): FirClassLikeSymbol<*>? {
return coneTypeSafe<ConeClassLikeType>()?.toSymbol(session)
@@ -181,16 +191,18 @@ fun CheckerContext.findClosestClassOrObject(): FirClass? {
*/
fun FirSimpleFunction.overriddenFunctions(
containingClass: FirClassSymbol<*>,
context: CheckerContext
context: CheckerContext,
memberRequiredPhase: FirResolvePhase?,
): List<FirFunctionSymbol<*>> {
return symbol.overriddenFunctions(containingClass, context)
return symbol.overriddenFunctions(containingClass, context, memberRequiredPhase)
}
fun FirNamedFunctionSymbol.overriddenFunctions(
containingClass: FirClassSymbol<*>,
context: CheckerContext
context: CheckerContext,
memberRequiredPhase: FirResolvePhase?,
): List<FirFunctionSymbol<*>> {
return overriddenFunctions(containingClass, context.session, context.scopeSession)
return overriddenFunctions(containingClass, context.session, context.scopeSession, memberRequiredPhase)
}
fun FirClass.collectSupertypesWithDelegates(): Map<FirTypeRef, FirFieldSymbol?> {
@@ -694,7 +706,12 @@ fun ConeKotlinType.getInlineClassUnderlyingType(session: FirSession): ConeKotlin
fun FirNamedFunctionSymbol.directOverriddenFunctions(session: FirSession, scopeSession: ScopeSession): List<FirNamedFunctionSymbol> {
val classSymbol = getContainingClassSymbol(session) as? FirClassSymbol ?: return emptyList()
val scope = classSymbol.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val scope = classSymbol.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = FirResolvePhase.STATUS,
)
scope.processFunctionsByName(name) { }
return scope.getDirectOverriddenFunctions(this, true)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -246,7 +246,8 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker<Fi
val scope = containingClass.unsubstitutedScope(
context.sessionHolder.session,
context.sessionHolder.scopeSession,
withForcedTypeCalculator = false
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
return findBiggestVisibility { checkVisibility ->
@@ -264,7 +265,8 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker<Fi
val scope = containingClass.unsubstitutedScope(
context.sessionHolder.session,
context.sessionHolder.scopeSession,
withForcedTypeCalculator = false
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
return findBiggestVisibility {
@@ -279,7 +281,8 @@ object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker<Fi
val scope = currentClassSymbol.unsubstitutedScope(
context.sessionHolder.session,
context.sessionHolder.scopeSession,
withForcedTypeCalculator = false
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
return findBiggestVisibility {
@@ -51,7 +51,7 @@ object FirCommonSessionFactory : FirAbstractSessionFactory() {
registerExtraComponents = {
registerExtraComponents(it)
},
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _ -> declaredMemberScope } },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _, _ -> declaredMemberScope } },
createProviders = { session, builtinsModuleData, kotlinScopeProvider ->
listOfNotNull(
MetadataSymbolProvider(
@@ -105,7 +105,7 @@ object FirCommonSessionFactory : FirAbstractSessionFactory() {
it.registerJsCheckers()
it.registerNativeCheckers()
},
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _ -> declaredMemberScope } },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _, _ -> declaredMemberScope } },
createProviders = { session, kotlinScopeProvider, symbolProvider, syntheticFunctionalInterfaceProvider, generatedSymbolsProvider, dependencies ->
var symbolProviderForBinariesFromIncrementalCompilation: MetadataSymbolProvider? = null
incrementalCompilationContext?.let {
@@ -49,7 +49,7 @@ object FirJsSessionFactory : FirAbstractSessionFactory() {
registerExtraComponents(session)
},
registerExtraCheckers = { it.registerJsCheckers() },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _ -> declaredMemberScope } },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _, _ -> declaredMemberScope } },
createProviders = { _, _, symbolProvider, generatedSymbolsProvider, syntheticFunctionInterfaceProvider, dependencies ->
listOfNotNull(
symbolProvider,
@@ -77,7 +77,7 @@ object FirJsSessionFactory : FirAbstractSessionFactory() {
it.registerJsSpecificResolveComponents()
registerExtraComponents(it)
},
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _ -> declaredMemberScope } },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _, _ -> declaredMemberScope } },
createProviders = { session, builtinsModuleData, kotlinScopeProvider ->
listOfNotNull(
KlibBasedSymbolProvider(session, moduleDataProvider, kotlinScopeProvider, resolvedLibraries),
@@ -36,7 +36,7 @@ object FirNativeSessionFactory : FirAbstractSessionFactory() {
moduleDataProvider,
languageVersionSettings,
registerExtraComponents,
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _ -> declaredMemberScope } },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _, _ -> declaredMemberScope } },
createProviders = { session, builtinsModuleData, kotlinScopeProvider ->
val forwardDeclarationsModuleData = BinaryModuleData.createDependencyModuleData(
Name.special("<forward declarations>"),
@@ -76,7 +76,7 @@ object FirNativeSessionFactory : FirAbstractSessionFactory() {
registerExtraComponents(session)
},
registerExtraCheckers = { it.registerNativeCheckers() },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _ -> declaredMemberScope } },
createKotlinScopeProvider = { FirKotlinScopeProvider { _, declaredMemberScope, _, _, _ -> declaredMemberScope } },
createProviders = { _, _, symbolProvider, generatedSymbolsProvider, syntheticFunctionInterfaceProvider, dependencies ->
listOfNotNull(
symbolProvider,
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -283,7 +283,7 @@ class FirElementSerializer private constructor(
private inline fun <reified T : FirCallableDeclaration, S : FirCallableSymbol<*>> FirClass.collectDeclarations(
processScope: (FirTypeScope, ((S) -> Unit)) -> Unit
): List<T> = buildList {
val memberScope = unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val memberScope = unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
processScope(memberScope) l@{
val declaration = it.fir as T
@@ -291,7 +291,7 @@ class FirElementSerializer private constructor(
// non-intersection or substitution fake override
if (!(declaration.isStatic || declaration is FirConstructor)) {
if (declaration.dispatchReceiverClassLookupTagOrNull()!= this@collectDeclarations.symbol.toLookupTag()) {
if (declaration.dispatchReceiverClassLookupTagOrNull() != this@collectDeclarations.symbol.toLookupTag()) {
return@l
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -380,7 +380,7 @@ internal fun FirSimpleFunction.processOverriddenFunctionSymbols(
containingClass: FirClass,
processor: (FirNamedFunctionSymbol) -> Unit
) {
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
scope.processFunctionsByName(name) {}
scope.processOverriddenFunctionsFromSuperClasses(symbol, containingClass) { overriddenSymbol ->
if (!session.visibilityChecker.isVisibleForOverriding(
@@ -454,7 +454,7 @@ internal fun FirProperty.processOverriddenPropertySymbols(
containingClass: FirClass,
processor: (FirPropertySymbol) -> Unit
): List<IrPropertySymbol> {
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
scope.processPropertiesByName(name) {}
val overriddenSet = mutableSetOf<IrPropertySymbol>()
scope.processOverriddenPropertiesFromSuperClasses(symbol, containingClass) { overriddenSymbol ->
@@ -488,7 +488,7 @@ internal fun FirProperty.generateOverriddenPropertySymbols(containingClass: FirC
context(Fir2IrComponents)
internal fun FirProperty.generateOverriddenAccessorSymbols(containingClass: FirClass, isGetter: Boolean): List<IrSimpleFunctionSymbol> {
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
scope.processPropertiesByName(name) {}
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
val superClasses = containingClass.getSuperTypesAsIrClasses() ?: return emptyList()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -76,10 +76,12 @@ class Fir2IrBuiltIns(
val constructorSymbol = if (firSymbol == null) {
owner.declarations.firstIsInstance<IrConstructor>().symbol
} else {
val firConstructorSymbol = firSymbol.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
.getDeclaredConstructors()
.singleOrNull()
?: return null
val firConstructorSymbol = firSymbol.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = true,
memberRequiredPhase = null,
).getDeclaredConstructors().singleOrNull() ?: return null
declarationStorage.getIrConstructorSymbol(firConstructorSymbol)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -206,7 +206,7 @@ class Fir2IrClassifierStorage(
}
private fun FirRegularClass.hasAbstractMembersInScope(): Boolean {
val scope = unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val scope = unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
val names = scope.getCallableNames()
var hasAbstract = false
for (name in names) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -175,7 +175,7 @@ class Fir2IrDeclarationStorage(
else -> {}
}
}
val scope = firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val scope = firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
scope.getCallableNames().forEach { callableName ->
buildList {
fakeOverrideGenerator.generateFakeOverridesForName(
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -128,8 +128,14 @@ class Fir2IrPluginContext(
val expandedClass = symbolProvider.getClassLikeSymbolByClassId(classId)
?.fullyExpandedClass(components.session)
?: return emptyList()
expandedClass
.unsubstitutedScope(components.session, components.scopeSession, withForcedTypeCalculator = true)
.unsubstitutedScope(
components.session,
components.scopeSession,
withForcedTypeCalculator = true,
memberRequiredPhase = null,
)
.getCallablesFromScope()
} else {
symbolProvider.getCallablesFromProvider()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -59,7 +59,7 @@ class FirIrProvider(val fir2IrComponents: Fir2IrComponents) : IrProvider {
val container = (getDeclarationForSignature(signature.container, SymbolKind.CLASS_SYMBOL)
?: getDeclarationForSignature(signature.container, SymbolKind.FUNCTION_SYMBOL)
?: getDeclarationForSignature(signature.container, SymbolKind.PROPERTY_SYMBOL)
) as IrTypeParametersContainer
) as IrTypeParametersContainer
val localSignature = signature.inner as IdSignature.LocalSignature
return container.typeParameters[localSignature.index()]
}
@@ -92,8 +92,13 @@ class FirIrProvider(val fir2IrComponents: Fir2IrComponents) : IrProvider {
}
isTopLevelPrivate = topLevelClass.visibility == Visibilities.Private
val classId = firClass.classId
val scope =
firClass.unsubstitutedScope(fir2IrComponents.session, fir2IrComponents.scopeSession, withForcedTypeCalculator = true)
val scope = firClass.unsubstitutedScope(
fir2IrComponents.session,
fir2IrComponents.scopeSession,
withForcedTypeCalculator = true,
memberRequiredPhase = null,
)
when (kind) {
SymbolKind.CLASS_SYMBOL -> {
firCandidates = listOf(firClass)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -645,11 +645,17 @@ class CallAndReferenceGenerator(
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass
var constructorSymbol: FirConstructorSymbol? = null
fir?.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)?.processDeclaredConstructors {
fir?.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = true,
memberRequiredPhase = null,
)?.processDeclaredConstructors {
if (it.fir.isPrimary && constructorSymbol == null) {
constructorSymbol = it
}
}
constructorSymbol?.let {
this.declarationStorage.getIrConstructorSymbol(it)
}
@@ -1068,7 +1074,10 @@ class CallAndReferenceGenerator(
private fun FirQualifiedAccessExpression.findIrExtensionReceiver(explicitReceiverExpression: IrExpression?): IrExpression? =
findIrReceiver(explicitReceiverExpression, isDispatch = false)
internal fun FirQualifiedAccessExpression.findIrReceiver(explicitReceiverExpression: IrExpression?, isDispatch: Boolean): IrExpression? {
internal fun FirQualifiedAccessExpression.findIrReceiver(
explicitReceiverExpression: IrExpression?,
isDispatch: Boolean,
): IrExpression? {
val firReceiver = if (isDispatch) dispatchReceiver else extensionReceiver
if (firReceiver == explicitReceiver) {
return explicitReceiverExpression
@@ -1084,7 +1093,10 @@ class CallAndReferenceGenerator(
}
}
private fun IrExpression.applyReceivers(qualifiedAccess: FirQualifiedAccessExpression, explicitReceiverExpression: IrExpression?): IrExpression {
private fun IrExpression.applyReceivers(
qualifiedAccess: FirQualifiedAccessExpression,
explicitReceiverExpression: IrExpression?,
): IrExpression {
when (this) {
is IrMemberAccessExpression<*> -> {
val ownerFunction =
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -197,7 +197,8 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
val scope = klass.unsubstitutedScope(
components.session,
components.scopeSession,
withForcedTypeCalculator = true
withForcedTypeCalculator = true,
memberRequiredPhase = null,
)
val contributedFunctionsInSupertypes =
buildMap<Name, FirSimpleFunction> {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -96,11 +96,23 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
fun generate(irField: IrField, firField: FirField, firSubClass: FirClass, subClass: IrClass) {
val subClassLookupTag = firSubClass.symbol.toLookupTag()
val subClassScope = firSubClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val subClassScope = firSubClass.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
val delegateToType = firField.initializer!!.typeRef.coneType.fullyExpandedType(session).lowerBoundIfFlexible()
val delegateToClass = delegateToType.toSymbol(session).boundClass()
val delegateToScope = delegateToClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val delegateToScope = delegateToClass.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
val delegateToLookupTag = (delegateToType as? ConeClassLikeType)?.lookupTag
subClassScope.processAllFunctions { functionSymbol ->
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -61,7 +61,13 @@ class FakeOverrideGenerator(
private fun IrClass.getFakeOverrides(klass: FirClass, realDeclarations: Collection<FirDeclaration>): List<IrDeclaration> {
val result = mutableListOf<IrDeclaration>()
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val useSiteMemberScope = klass.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = true,
memberRequiredPhase = null,
)
val superTypesCallableNames = useSiteMemberScope.getCallableNames()
val realDeclarationSymbols = realDeclarations.mapTo(mutableSetOf(), FirDeclaration::symbol)
@@ -76,7 +82,13 @@ class FakeOverrideGenerator(
name: Name,
firClass: FirClass
): List<IrDeclaration> = buildList {
val useSiteMemberScope = firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val useSiteMemberScope = firClass.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = true,
memberRequiredPhase = null,
)
generateFakeOverridesForName(
irClass, useSiteMemberScope, name, firClass, this,
// This parameter is only needed for data-class methods that is irrelevant for lazy library classes
@@ -202,7 +214,7 @@ class FakeOverrideGenerator(
fakeOverride: IrSimpleFunction,
originalSymbol: FirNamedFunctionSymbol,
) {
val scope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val scope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
val classLookupTag = klass.symbol.toLookupTag()
val baseFirSymbolsForFakeOverride =
if (originalSymbol.shouldHaveComputedBaseSymbolsForClass(classLookupTag)) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -154,7 +154,7 @@ class Fir2IrLazyClass(
val result = mutableListOf<IrDeclaration>()
// NB: it's necessary to take all callables from scope,
// e.g. to avoid accessing un-enhanced Java declarations with FirJavaTypeRef etc. inside
val scope = fir.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val scope = fir.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
scope.processDeclaredConstructors {
if (shouldBuildStub(it.fir)) {
result += declarationStorage.getIrConstructorSymbol(it, forceTopLevelPrivate = isTopLevelPrivate).owner
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.utils.classId
import org.jetbrains.kotlin.fir.declarations.utils.isJava
import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes
@@ -30,10 +31,11 @@ object JavaScopeProvider : FirScopeProvider() {
override fun getUseSiteMemberScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope {
val symbol = klass.symbol as FirRegularClassSymbol
val enhancementScope = buildJavaEnhancementScope(useSiteSession, symbol, scopeSession)
val enhancementScope = buildJavaEnhancementScope(useSiteSession, symbol, scopeSession, memberRequiredPhase)
if (klass.classKind == ClassKind.ANNOTATION_CLASS) {
return buildSyntheticScopeForAnnotations(useSiteSession, symbol, scopeSession, enhancementScope)
}
@@ -54,7 +56,8 @@ object JavaScopeProvider : FirScopeProvider() {
private fun buildJavaEnhancementScope(
useSiteSession: FirSession,
symbol: FirRegularClassSymbol,
scopeSession: ScopeSession
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): JavaClassMembersEnhancementScope {
return scopeSession.getOrBuild(symbol, JAVA_ENHANCEMENT) {
val firJavaClass = symbol.fir
@@ -64,7 +67,7 @@ object JavaScopeProvider : FirScopeProvider() {
JavaClassMembersEnhancementScope(
useSiteSession,
symbol,
buildUseSiteMemberScopeWithJavaTypes(firJavaClass, useSiteSession, scopeSession)
buildUseSiteMemberScopeWithJavaTypes(firJavaClass, useSiteSession, scopeSession, memberRequiredPhase)
)
}
}
@@ -81,6 +84,7 @@ object JavaScopeProvider : FirScopeProvider() {
regularClass: FirJavaClass,
useSiteSession: FirSession,
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): JavaClassUseSiteMemberScope {
return scopeSession.getOrBuild(regularClass.symbol, JAVA_USE_SITE) {
val declaredScope = buildDeclaredMemberScope(useSiteSession, regularClass)
@@ -93,7 +97,7 @@ object JavaScopeProvider : FirScopeProvider() {
)
val superTypeScopes = superTypes.mapNotNull {
it.scopeForSupertype(useSiteSession, scopeSession, regularClass)
it.scopeForSupertype(useSiteSession, scopeSession, regularClass, memberRequiredPhase = memberRequiredPhase)
}
JavaClassUseSiteMemberScope(
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.FirImplicitBuiltinTypeRef
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.name.StandardClassIds
class JvmSupertypeUpdater(private val session: FirSession) : PlatformSupertypeUpdater() {
@@ -98,7 +97,7 @@ class JvmSupertypeUpdater(private val session: FirSession) : PlatformSupertypeUp
}
val recordConstructorSymbol = recordType.lookupTag.toFirRegularClassSymbol(session)
?.unsubstitutedScope(session, data, withForcedTypeCalculator = false)
?.unsubstitutedScope(session, data, withForcedTypeCalculator = false, memberRequiredPhase = null)
?.getDeclaredConstructors()
?.firstOrNull { it.fir.valueParameters.isEmpty() }
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.utils.classId
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
@@ -25,7 +26,8 @@ fun wrapScopeWithJvmMapped(
klass: FirClass,
declaredMemberScope: FirContainingNamesAwareScope,
useSiteSession: FirSession,
scopeSession: ScopeSession
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): FirContainingNamesAwareScope {
val classId = klass.classId
val kotlinUnsafeFqName = classId.asSingleFqName().toUnsafe()
@@ -36,7 +38,12 @@ fun wrapScopeWithJvmMapped(
?: return declaredMemberScope
val preparedSignatures = JvmMappedScope.prepareSignatures(javaClass, JavaToKotlinClassMap.isMutable(kotlinUnsafeFqName))
return if (preparedSignatures.isNotEmpty()) {
javaClass.unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false).let { javaClassUseSiteScope ->
javaClass.unsubstitutedScope(
useSiteSession,
scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = memberRequiredPhase,
).let { javaClassUseSiteScope ->
val jvmMappedScope = JvmMappedScope(
useSiteSession,
klass,
@@ -92,7 +92,7 @@ object OperatorFunctionChecks {
val containingClassSymbol = function.containingClassLookupTag()?.toFirRegularClassSymbol(session) ?: return null
val customEqualsSupported = session.languageVersionSettings.supportsFeature(LanguageFeature.CustomEqualsInValueClasses)
if (function.symbol.overriddenFunctions(containingClassSymbol, session, scopeSession)
if (function.symbol.overriddenFunctions(containingClassSymbol, session, scopeSession, memberRequiredPhase = null)
.any { it.containingClassLookupTag()?.classId == StandardClassIds.Any }
|| (customEqualsSupported && function.isTypedEqualsInValueClass(session))
) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -124,7 +124,7 @@ private fun ConeClassLikeType.classScope(
)
}
return fir.scopeForClass(substitutor, useSiteSession, scopeSession, memberOwnerLookupTag)
return fir.scopeForClass(substitutor, useSiteSession, scopeSession, memberOwnerLookupTag, requiredPhase)
}
private fun ConeClassLikeType.obtainFirOfClass(useSiteSession: FirSession, requiredPhase: FirResolvePhase): FirClass? {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSessionComponent
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.utils.delegateFields
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
import org.jetbrains.kotlin.fir.resolve.*
@@ -20,6 +21,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.*
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhaseWithCallableMembers
import org.jetbrains.kotlin.fir.types.*
class FirKotlinScopeProvider(
@@ -27,19 +29,21 @@ class FirKotlinScopeProvider(
klass: FirClass,
declaredMemberScope: FirContainingNamesAwareScope,
useSiteSession: FirSession,
scopeSession: ScopeSession
) -> FirContainingNamesAwareScope = { _, declaredMemberScope, _, _ -> declaredMemberScope }
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
) -> FirContainingNamesAwareScope = { _, declaredMemberScope, _, _, _ -> declaredMemberScope }
) : FirScopeProvider(), FirSessionComponent {
override fun getUseSiteMemberScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope {
return scopeSession.getOrBuild(klass.symbol, USE_SITE) {
val declaredScope = useSiteSession.declaredMemberScope(klass)
val decoratedDeclaredMemberScope =
declaredMemberScopeDecorator(klass, declaredScope, useSiteSession, scopeSession).let {
declaredMemberScopeDecorator(klass, declaredScope, useSiteSession, scopeSession, memberRequiredPhase).let {
val delegateFields = klass.delegateFields
if (delegateFields.isEmpty())
it
@@ -50,7 +54,7 @@ class FirKotlinScopeProvider(
val scopes = lookupSuperTypes(
klass, lookupInterfaces = true, deep = false, useSiteSession = useSiteSession, substituteTypes = true
).mapNotNull { useSiteSuperType ->
useSiteSuperType.scopeForSupertype(useSiteSession, scopeSession, klass)
useSiteSuperType.scopeForSupertype(useSiteSession, scopeSession, klass, memberRequiredPhase = memberRequiredPhase)
}
FirClassUseSiteMemberScope(
klass,
@@ -92,9 +96,10 @@ data class ConeSubstitutionScopeKey(
fun FirClass.unsubstitutedScope(
useSiteSession: FirSession,
scopeSession: ScopeSession,
withForcedTypeCalculator: Boolean
withForcedTypeCalculator: Boolean,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope {
val scope = scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession)
val scope = scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession, memberRequiredPhase)
if (withForcedTypeCalculator) return FirScopeWithFakeOverrideTypeCalculator(scope, FakeOverrideTypeCalculator.Forced)
return scope
}
@@ -102,29 +107,33 @@ fun FirClass.unsubstitutedScope(
fun FirClassSymbol<*>.unsubstitutedScope(
useSiteSession: FirSession,
scopeSession: ScopeSession,
withForcedTypeCalculator: Boolean
withForcedTypeCalculator: Boolean,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope {
return fir.unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator)
return fir.unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator, memberRequiredPhase)
}
fun FirClass.scopeForClass(
substitutor: ConeSubstitutor,
useSiteSession: FirSession,
scopeSession: ScopeSession,
memberOwnerLookupTag: ConeClassLikeLookupTag
memberOwnerLookupTag: ConeClassLikeLookupTag,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope = scopeForClassImpl(
substitutor, useSiteSession, scopeSession,
skipPrivateMembers = false,
classFirDispatchReceiver = this,
// TODO: why it's always false?
isFromExpectClass = false,
memberOwnerLookupTag = memberOwnerLookupTag
memberOwnerLookupTag = memberOwnerLookupTag,
memberRequiredPhase = memberRequiredPhase,
)
fun ConeKotlinType.scopeForSupertype(
useSiteSession: FirSession,
scopeSession: ScopeSession,
derivedClass: FirClass,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope? {
if (this !is ConeClassLikeType) return null
if (this is ConeErrorType) return null
@@ -143,7 +152,8 @@ fun ConeKotlinType.scopeForSupertype(
skipPrivateMembers = true,
classFirDispatchReceiver = derivedClass,
isFromExpectClass = (derivedClass as? FirRegularClass)?.isExpect == true,
memberOwnerLookupTag = derivedClass.symbol.toLookupTag()
memberOwnerLookupTag = derivedClass.symbol.toLookupTag(),
memberRequiredPhase = memberRequiredPhase,
)
}
@@ -160,9 +170,14 @@ private fun FirClass.scopeForClassImpl(
skipPrivateMembers: Boolean,
classFirDispatchReceiver: FirClass,
isFromExpectClass: Boolean,
memberOwnerLookupTag: ConeClassLikeLookupTag?
memberOwnerLookupTag: ConeClassLikeLookupTag?,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope {
val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false)
memberRequiredPhase?.let {
lazyResolveToPhaseWithCallableMembers(it)
}
val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase)
if (substitutor == ConeSubstitutor.Empty) return basicScope
val key = ConeSubstitutionScopeKey(
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -58,12 +58,14 @@ fun debugCollectOverrides(symbol: FirCallableSymbol<*>, scope: FirTypeScope): Ma
fun FirNamedFunctionSymbol.overriddenFunctions(
containingClass: FirClassSymbol<*>,
session: FirSession,
scopeSession: ScopeSession
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): List<FirFunctionSymbol<*>> {
val firTypeScope = containingClass.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = true
withForcedTypeCalculator = true,
memberRequiredPhase = memberRequiredPhase,
)
val overriddenFunctions = mutableListOf<FirFunctionSymbol<*>>()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -17,6 +17,8 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.coneTypeSafe
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
@@ -35,7 +37,7 @@ abstract class FirAbstractImportingScope(
private fun FirClassSymbol<*>.getStaticsScope(): FirContainingNamesAwareScope? =
if (fir.classKind == ClassKind.OBJECT) {
unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = FirResolvePhase.STATUS)
} else {
fir.scopeProvider.getStaticScope(fir, session, scopeSession)
}
@@ -181,7 +181,8 @@ fun ConeClassLikeType.findBaseInvokeSymbol(session: FirSession, scopeSession: Sc
functionN.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = false
withForcedTypeCalculator = false,
memberRequiredPhase = null,
).processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol ->
baseInvokeSymbol = functionSymbol
return@processFunctionsByName
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.builder
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.scopes.FirContainingNamesAwareScope
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
@@ -16,20 +17,19 @@ object StubFirScopeProvider : FirScopeProvider() {
override fun getUseSiteMemberScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirTypeScope {
error("Stub")
}
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope = error("Stub")
override fun getStaticMemberScopeForCallables(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
): FirContainingNamesAwareScope? {
return null
}
): FirContainingNamesAwareScope? = null
override fun getNestedClassifierScope(klass: FirClass, useSiteSession: FirSession, scopeSession: ScopeSession): FirContainingNamesAwareScope? {
return null
}
override fun getNestedClassifierScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession,
): FirContainingNamesAwareScope? = null
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -549,7 +549,8 @@ class FirCallResolver(
annotationClassSymbol.fir.unsubstitutedScope(
session,
components.scopeSession,
withForcedTypeCalculator = false
withForcedTypeCalculator = false,
memberRequiredPhase = null,
).processDeclaredConstructors {
if (it.fir.isPrimary && constructorSymbol == null) {
constructorSymbol = it
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -35,7 +35,8 @@ class FirDefaultParametersResolver : FirSessionComponent {
ConeSubstitutor.Empty,
session,
scopeSession,
containingClass.symbol.toLookupTag()
containingClass.symbol.toLookupTag(),
memberRequiredPhase = null,
)
}
else -> return false
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -323,7 +323,12 @@ private fun FirRegularClass.findSingleAbstractMethodByNames(
var resultMethod: FirSimpleFunction? = null
var metIncorrectMember = false
val classUseSiteMemberScope = this.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val classUseSiteMemberScope = this.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
for (candidateName in samCandidateNames) {
if (metIncorrectMember) break
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -203,7 +203,8 @@ private fun processConstructors(
substitutor,
session,
bodyResolveComponents.scopeSession,
firClass.symbol.toLookupTag()
firClass.symbol.toLookupTag(),
memberRequiredPhase = FirResolvePhase.STATUS,
)
}
}
@@ -1,12 +1,12 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.resolve.transformers
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.declarations.impl.FirOuterClassTypeParameterRef
@@ -15,12 +15,17 @@ import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
import org.jetbrains.kotlin.fir.declarations.utils.isOverride
import org.jetbrains.kotlin.fir.declarations.utils.visibility
import org.jetbrains.kotlin.fir.extensions.*
import org.jetbrains.kotlin.fir.extensions.FirStatusTransformerExtension
import org.jetbrains.kotlin.fir.extensions.extensionService
import org.jetbrains.kotlin.fir.extensions.statusTransformerExtensions
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
import org.jetbrains.kotlin.fir.toEffectiveVisibility
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.visibilityChecker
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.runIf
@@ -86,7 +91,7 @@ class FirStatusResolver(
return emptyList()
}
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
return buildList {
scope.processPropertiesByName(property.name) {}
@@ -124,7 +129,13 @@ class FirStatusResolver(
}
return buildList<FirCallableDeclaration> {
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val scope = containingClass.unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = null,
)
val symbol = function.symbol
scope.processFunctionsByName(function.name) {}
scope.processDirectOverriddenFunctionsWithBaseScope(symbol) { overriddenSymbol, _ ->
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -55,7 +55,13 @@ object FirExpectActualResolver {
val actualTypeParameters = actualContainingClass
?.typeParameterSymbols
.orEmpty()
parentSubstitutor = createExpectActualTypeParameterSubstitutor(expectTypeParameters, actualTypeParameters, useSiteSession)
parentSubstitutor = createExpectActualTypeParameterSubstitutor(
expectTypeParameters,
actualTypeParameters,
useSiteSession,
)
when (actualSymbol) {
is FirConstructorSymbol -> expectContainingClass?.getConstructors(scopeSession)
else -> expectContainingClass?.getMembers(callableId.callableName, scopeSession)
@@ -283,7 +289,12 @@ object FirExpectActualResolver {
return ExpectActualCompatibility.Incompatible.TypeParameterCount
}
val substitutor = createExpectActualTypeParameterSubstitutor(expectedTypeParameters, actualTypeParameters, actualSession, parentSubstitutor)
val substitutor = createExpectActualTypeParameterSubstitutor(
expectedTypeParameters,
actualTypeParameters,
actualSession,
parentSubstitutor,
)
if (
!areCompatibleTypeLists(
@@ -551,10 +562,16 @@ object FirExpectActualResolver {
private fun FirClassSymbol<*>.getConstructors(
scopeSession: ScopeSession,
session: FirSession = moduleData.session
): Collection<FirConstructorSymbol> {
return mutableListOf<FirConstructorSymbol>().apply {
getConstructorsTo(this, unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false))
}
): Collection<FirConstructorSymbol> = mutableListOf<FirConstructorSymbol>().apply {
getConstructorsTo(
this,
unsubstitutedScope(
session,
scopeSession,
withForcedTypeCalculator = false,
memberRequiredPhase = FirResolvePhase.STATUS,
)
)
}
private fun getConstructorsTo(destination: MutableList<in FirConstructorSymbol>, scope: FirTypeScope) {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -7,13 +7,15 @@ package org.jetbrains.kotlin.fir.scopes
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.resolve.ScopeSession
abstract class FirScopeProvider {
abstract fun getUseSiteMemberScope(
klass: FirClass,
useSiteSession: FirSession,
scopeSession: ScopeSession
scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?,
): FirTypeScope
abstract fun getStaticMemberScopeForCallables(
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -84,7 +84,7 @@ class FirScopeDumpHandler(testServices: TestServices) : FirAnalysisHandler(testS
println("$fqName: ")
session.lazyDeclarationResolver.disableLazyResolveContractChecksInside {
val scope = firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
val scope = firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true, memberRequiredPhase = null)
val names = namesFromDirective.takeIf { it.isNotEmpty() }?.map { Name.identifier(it) } ?: scope.getCallableNames()
withIndent {
for (name in names) {
@@ -30,7 +30,7 @@ class AllPropertiesConstructorMetadataProvider(session: FirSession) : FirDeclara
override fun provideDeclarationsForClass(klass: FirClass, scopeSession: ScopeSession): List<FirDeclaration> {
if (!session.predicateBasedProvider.matches(PREDICATE, klass)) return emptyList()
val scope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
val scope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase = null)
val properties = scope.getCallableNames()
.flatMap { scope.getProperties(it) }
.sortedBy { it.containingClassLookupTag() == klass.symbol.toLookupTag() }
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -13,18 +13,25 @@ import org.jetbrains.kotlin.fir.analysis.checkers.getContainingDeclarationSymbol
import org.jetbrains.kotlin.fir.containingClassForStaticMemberAttr
import org.jetbrains.kotlin.fir.copy
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.builder.*
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunctionCopy
import org.jetbrains.kotlin.fir.declarations.origin
import org.jetbrains.kotlin.fir.declarations.utils.isCompanion
import org.jetbrains.kotlin.fir.extensions.*
import org.jetbrains.kotlin.fir.plugin.*
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.scopes.*
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
import org.jetbrains.kotlin.fir.scopes.getFunctions
import org.jetbrains.kotlin.fir.scopes.getProperties
import org.jetbrains.kotlin.fir.scopes.impl.toConeType
import org.jetbrains.kotlin.fir.scopes.scopeForSupertype
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.ConeTypeProjection
import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.fir.types.constructClassLikeType
import org.jetbrains.kotlin.fir.types.constructType
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
@@ -140,7 +147,7 @@ class SerializationFirResolveExtension(session: FirSession) : FirDeclarationGene
val scopes = lookupSuperTypes(
owner, lookupInterfaces = true, deep = false, useSiteSession = session
).mapNotNull { useSiteSuperType ->
useSiteSuperType.scopeForSupertype(session, scopeSession, owner.fir)
useSiteSuperType.scopeForSupertype(session, scopeSession, owner.fir, memberRequiredPhase = null)
}
val targets = scopes.flatMap { extractor(it) }
return targets.singleOrNull() ?: error("Multiple overrides found for ${callableId.callableName}")