[FIR] Add wrapping scopes with forced calculator in checkers and fir2ir
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
|
||||
fun renderJavaClass(renderer: FirRenderer, javaClass: FirJavaClass, session: FirSession) {
|
||||
val memberScope = javaClass.unsubstitutedScope(session, ScopeSession())
|
||||
val memberScope = javaClass.unsubstitutedScope(session, ScopeSession(), withForcedTypeCalculator = true)
|
||||
|
||||
val staticScope = javaClass.scopeProvider.getStaticScope(javaClass, session, ScopeSession())
|
||||
|
||||
|
||||
@@ -208,7 +208,8 @@ fun FirSimpleFunction.overriddenFunctions(
|
||||
): List<FirFunctionSymbol<*>> {
|
||||
val firTypeScope = containingClass.unsubstitutedScope(
|
||||
context.sessionHolder.session,
|
||||
context.sessionHolder.scopeSession
|
||||
context.sessionHolder.scopeSession,
|
||||
withForcedTypeCalculator = true
|
||||
)
|
||||
|
||||
val overriddenFunctions = mutableListOf<FirFunctionSymbol<*>>()
|
||||
|
||||
+2
-1
@@ -36,7 +36,8 @@ object FirTypeMismatchOnOverrideChecker : FirRegularClassChecker() {
|
||||
|
||||
val firTypeScope = declaration.unsubstitutedScope(
|
||||
context.sessionHolder.session,
|
||||
context.sessionHolder.scopeSession
|
||||
context.sessionHolder.scopeSession,
|
||||
withForcedTypeCalculator = true
|
||||
)
|
||||
|
||||
for (it in declaration.declarations) {
|
||||
|
||||
@@ -230,7 +230,7 @@ internal fun FirSimpleFunction.generateOverriddenFunctionSymbols(
|
||||
scopeSession: ScopeSession,
|
||||
declarationStorage: Fir2IrDeclarationStorage
|
||||
): List<IrSimpleFunctionSymbol> {
|
||||
val scope = containingClass.unsubstitutedScope(session, scopeSession)
|
||||
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||
scope.processFunctionsByName(name) {}
|
||||
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
||||
scope.processDirectlyOverriddenFunctions(symbol) {
|
||||
@@ -251,7 +251,7 @@ internal fun FirProperty.generateOverriddenAccessorSymbols(
|
||||
scopeSession: ScopeSession,
|
||||
declarationStorage: Fir2IrDeclarationStorage
|
||||
): List<IrSimpleFunctionSymbol> {
|
||||
val scope = containingClass.unsubstitutedScope(session, scopeSession)
|
||||
val scope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||
scope.processPropertiesByName(name) {}
|
||||
val overriddenSet = mutableSetOf<IrSimpleFunctionSymbol>()
|
||||
scope.processDirectlyOverriddenProperties(symbol) {
|
||||
|
||||
+1
-1
@@ -368,7 +368,7 @@ class CallAndReferenceGenerator(
|
||||
// Fallback for FirReferencePlaceholderForResolvedAnnotations from jar
|
||||
val fir = coneType.lookupTag.toSymbol(session)?.fir as? FirClass<*>
|
||||
var constructorSymbol: FirConstructorSymbol? = null
|
||||
fir?.unsubstitutedScope(session, scopeSession)?.processDeclaredConstructors {
|
||||
fir?.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)?.processDeclaredConstructors {
|
||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||
constructorSymbol = it
|
||||
}
|
||||
|
||||
+5
-1
@@ -146,7 +146,11 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
buildMap<Name, FirSimpleFunction> {
|
||||
for (name in listOf(equalsName, hashCodeName, toStringName)) {
|
||||
klass.unsubstitutedScope(components.session, components.scopeSession).processFunctionsByName(name) {
|
||||
klass.unsubstitutedScope(
|
||||
components.session,
|
||||
components.scopeSession,
|
||||
withForcedTypeCalculator = true
|
||||
).processFunctionsByName(name) {
|
||||
val declaration = it.fir
|
||||
if (declaration is FirSimpleFunction &&
|
||||
declaration.matchesDataClassSyntheticMemberSignatures
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ internal class DelegatedMemberGenerator(
|
||||
fun generate(irField: IrField, firField: FirField, firSubClass: FirClass<*>, subClass: IrClass) {
|
||||
val subClassLookupTag = firSubClass.symbol.toLookupTag()
|
||||
|
||||
val subClassScope = firSubClass.unsubstitutedScope(session, scopeSession)
|
||||
val subClassScope = firSubClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||
subClassScope.processAllFunctions { functionSymbol ->
|
||||
if (functionSymbol !is FirNamedFunctionSymbol) return@processAllFunctions
|
||||
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ class FakeOverrideGenerator(
|
||||
|
||||
fun IrClass.getFakeOverrides(klass: FirClass<*>, realDeclarations: Collection<FirDeclaration>): List<IrDeclaration> {
|
||||
val result = mutableListOf<IrDeclaration>()
|
||||
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession)
|
||||
val useSiteMemberScope = klass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||
val superTypesCallableNames = useSiteMemberScope.getCallableNames()
|
||||
val realDeclarationSymbols = realDeclarations.filterIsInstance<FirSymbolOwner<*>>().mapTo(mutableSetOf(), FirSymbolOwner<*>::symbol)
|
||||
for (name in superTypesCallableNames) {
|
||||
|
||||
@@ -123,7 +123,7 @@ class Fir2IrLazyClass(
|
||||
val processedNames = mutableSetOf<Name>()
|
||||
// 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)
|
||||
val scope = fir.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = true)
|
||||
scope.processDeclaredConstructors {
|
||||
result += declarationStorage.getIrConstructorSymbol(it).owner
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ fun wrapScopeWithJvmMapped(
|
||||
?: return declaredMemberScope
|
||||
val preparedSignatures = JvmMappedScope.prepareSignatures(javaClass)
|
||||
return if (preparedSignatures.isNotEmpty()) {
|
||||
javaClass.unsubstitutedScope(useSiteSession, scopeSession).let { javaClassUseSiteScope ->
|
||||
javaClass.unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false).let { javaClassUseSiteScope ->
|
||||
val jvmMappedScope = JvmMappedScope(declaredMemberScope, javaClassUseSiteScope, preparedSignatures)
|
||||
if (klass !is FirRegularClass) {
|
||||
jvmMappedScope
|
||||
|
||||
@@ -386,7 +386,11 @@ class FirCallResolver(
|
||||
callInfo: CallInfo
|
||||
): ResolutionResult? {
|
||||
var constructorSymbol: FirConstructorSymbol? = null
|
||||
annotationClassSymbol.fir.unsubstitutedScope(session, components.scopeSession).processDeclaredConstructors {
|
||||
annotationClassSymbol.fir.unsubstitutedScope(
|
||||
session,
|
||||
components.scopeSession,
|
||||
withForcedTypeCalculator = false
|
||||
).processDeclaredConstructors {
|
||||
if (it.fir.isPrimary && constructorSymbol == null) {
|
||||
constructorSymbol = it
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ fun FirSimpleFunction.lowestVisibilityAmongOverrides(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
): Visibility {
|
||||
val firTypeScope = containingClass.unsubstitutedScope(session, scopeSession)
|
||||
val firTypeScope = containingClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
|
||||
var visibility = visibility
|
||||
|
||||
// required; otherwise processOverriddenFunctions()
|
||||
|
||||
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.resolve
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
|
||||
@@ -260,7 +259,7 @@ private fun FirRegularClass.findSingleAbstractMethodByNames(
|
||||
var resultMethod: FirSimpleFunction? = null
|
||||
var metIncorrectMember = false
|
||||
|
||||
val classUseSiteMemberScope = this.unsubstitutedScope(session, scopeSession)
|
||||
val classUseSiteMemberScope = this.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false)
|
||||
|
||||
for (candidateName in samCandidateNames) {
|
||||
if (metIncorrectMember) break
|
||||
|
||||
+5
-1
@@ -85,7 +85,11 @@ fun ConeClassLikeType.findBaseInvokeSymbol(session: FirSession, scopeSession: Sc
|
||||
require(this.isBuiltinFunctionalType(session))
|
||||
val functionN = (lookupTag.toSymbol(session)?.fir as? FirClass<*>) ?: return null
|
||||
var baseInvokeSymbol: FirFunctionSymbol<*>? = null
|
||||
functionN.unsubstitutedScope(session, scopeSession).processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol ->
|
||||
functionN.unsubstitutedScope(
|
||||
session,
|
||||
scopeSession,
|
||||
withForcedTypeCalculator = false
|
||||
).processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol ->
|
||||
baseInvokeSymbol = functionSymbol
|
||||
return@processFunctionsByName
|
||||
}
|
||||
|
||||
@@ -96,8 +96,14 @@ data class ConeSubstitutionScopeKey(
|
||||
|
||||
data class DelegatedMemberScopeKey(val callableId: CallableId) : ScopeSessionKey<FirField, FirDelegatedMemberScope>()
|
||||
|
||||
fun FirClass<*>.unsubstitutedScope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope {
|
||||
return scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession)
|
||||
fun FirClass<*>.unsubstitutedScope(
|
||||
useSiteSession: FirSession,
|
||||
scopeSession: ScopeSession,
|
||||
withForcedTypeCalculator: Boolean
|
||||
): FirTypeScope {
|
||||
val scope = scopeProvider.getUseSiteMemberScope(this, useSiteSession, scopeSession)
|
||||
if (withForcedTypeCalculator) return FirScopeWithFakeOverrideTypeCalculator(scope, FakeOverrideTypeCalculator.Forced)
|
||||
return scope
|
||||
}
|
||||
|
||||
fun FirClass<*>.scopeForClass(
|
||||
@@ -143,7 +149,7 @@ private fun FirClass<*>.scopeForClassImpl(
|
||||
containingClassForAdditionalMembers: ConeClassLikeLookupTag,
|
||||
isFromExpectClass: Boolean
|
||||
): FirTypeScope {
|
||||
val basicScope = unsubstitutedScope(useSiteSession, scopeSession)
|
||||
val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false)
|
||||
if (substitutor == ConeSubstitutor.Empty) return basicScope
|
||||
|
||||
return scopeSession.getOrBuild(
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ abstract class FirAbstractImportingScope(
|
||||
val firClass = (symbol as FirClassSymbol<*>).fir
|
||||
|
||||
return if (firClass.classKind == ClassKind.OBJECT)
|
||||
FirObjectImportedCallableScope(classId, firClass.unsubstitutedScope(session, scopeSession))
|
||||
FirObjectImportedCallableScope(classId, firClass.unsubstitutedScope(session, scopeSession, withForcedTypeCalculator = false))
|
||||
else
|
||||
firClass.scopeProvider.getStaticScope(firClass, session, scopeSession)
|
||||
}
|
||||
|
||||
+5
-1
@@ -59,7 +59,11 @@ internal class KtFirScopeProvider(
|
||||
val firScope =
|
||||
classSymbol.firRef.withFir(FirResolvePhase.SUPER_TYPES) { fir ->
|
||||
val firSession = fir.session
|
||||
fir.unsubstitutedScope(firSession, firResolveState.firTransformerProvider.getScopeSession(firSession))
|
||||
fir.unsubstitutedScope(
|
||||
firSession,
|
||||
firResolveState.firTransformerProvider.getScopeSession(firSession),
|
||||
withForcedTypeCalculator = false
|
||||
)
|
||||
}.also(firScopeStorage::register)
|
||||
KtFirMemberScope(classSymbol, firScope, token, builder)
|
||||
}
|
||||
|
||||
+3
-2
@@ -49,7 +49,8 @@ internal class KtFirSymbolDeclarationOverridesProvider(
|
||||
|
||||
val firTypeScope = containingDeclaration.unsubstitutedScope(
|
||||
containingDeclaration.session,
|
||||
ScopeSession()
|
||||
ScopeSession(),
|
||||
withForcedTypeCalculator = false
|
||||
)
|
||||
|
||||
val overriddenElement = mutableSetOf<KtCallableSymbol>()
|
||||
@@ -64,4 +65,4 @@ internal class KtFirSymbolDeclarationOverridesProvider(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user