[FIR] rename requiredPhase to requiredMembersPhase for type scope

Also move `requiredMembersPhase` use inside `unsubstitutedScope`

^KT-56551
This commit is contained in:
Dmitrii Gridin
2023-05-14 17:31:44 +02:00
committed by Space Team
parent 52ce302095
commit aaf173687b
18 changed files with 193 additions and 125 deletions
@@ -279,7 +279,7 @@ internal class KtFirScopeProvider(
firResolveSession.useSiteFirSession, firResolveSession.useSiteFirSession,
getScopeSession(), getScopeSession(),
FakeOverrideTypeCalculator.Forced, FakeOverrideTypeCalculator.Forced,
requiredPhase = FirResolvePhase.STATUS, requiredMembersPhase = FirResolvePhase.STATUS,
) )
} }
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -234,8 +234,9 @@ internal object FirReferenceResolveHelper {
session, session,
analysisSession.getScopeSessionFor(analysisSession.useSiteSession), analysisSession.getScopeSessionFor(analysisSession.useSiteSession),
FakeOverrideTypeCalculator.DoNothing, FakeOverrideTypeCalculator.DoNothing,
requiredPhase = FirResolvePhase.STATUS requiredMembersPhase = FirResolvePhase.STATUS,
) ?: return emptyList() ) ?: return emptyList()
return buildList { return buildList {
scope.processFunctionsByName(OperatorNameConventions.EQUALS) { functionSymbol -> scope.processFunctionsByName(OperatorNameConventions.EQUALS) { functionSymbol ->
val parameterSymbol = functionSymbol.valueParameterSymbols.singleOrNull() val parameterSymbol = functionSymbol.valueParameterSymbols.singleOrNull()
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -56,8 +56,9 @@ internal class KtFirPropertySetterSymbol(
session, session,
analysisSession.getScopeSessionFor(session), analysisSession.getScopeSessionFor(session),
FakeOverrideTypeCalculator.DoNothing, FakeOverrideTypeCalculator.DoNothing,
requiredPhase = FirResolvePhase.STATUS, requiredMembersPhase = FirResolvePhase.STATUS,
) ?: return false ) ?: return false
val overriddenProperties = containingClassScope.getDirectOverriddenProperties(propertySymbol) val overriddenProperties = containingClassScope.getDirectOverriddenProperties(propertySymbol)
overriddenProperties.any { it.isVar } overriddenProperties.any { it.isVar }
} }
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -212,13 +212,17 @@ abstract class AbstractAnnotationDeserializer(
val symbol = lookupTag.toSymbol(session) val symbol = lookupTag.toSymbol(session)
val firAnnotationClass = (symbol as? FirRegularClassSymbol)?.fir ?: return@lazy null val firAnnotationClass = (symbol as? FirRegularClassSymbol)?.fir ?: return@lazy null
val classScope = val classScope = firAnnotationClass.defaultType().scope(
firAnnotationClass.defaultType() useSiteSession = session,
.scope(session, ScopeSession(), FakeOverrideTypeCalculator.DoNothing, requiredPhase = null) scopeSession = ScopeSession(),
?: error("Null scope for $classId") fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = null,
) ?: error("Null scope for $classId")
val constructor = val constructor = classScope.getDeclaredConstructors()
classScope.getDeclaredConstructors().singleOrNull()?.fir ?: error("No single constructor found for $classId") .singleOrNull()
?.fir
?: error("No single constructor found for $classId")
constructor.valueParameters.associateBy { it.name } constructor.valueParameters.associateBy { it.name }
} }
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.getOrBuildScopeForIntegerConstantOpe
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
@@ -28,21 +27,26 @@ import org.jetbrains.kotlin.name.ClassId
fun FirSmartCastExpression.smartcastScope( fun FirSmartCastExpression.smartcastScope(
useSiteSession: FirSession, useSiteSession: FirSession,
scopeSession: ScopeSession, scopeSession: ScopeSession,
requiredPhase: FirResolvePhase? = null, requiredMembersPhase: FirResolvePhase? = null,
): FirTypeScope? { ): FirTypeScope? {
val smartcastType = smartcastTypeWithoutNullableNothing?.coneType ?: smartcastType.coneType val smartcastType = smartcastTypeWithoutNullableNothing?.coneType ?: smartcastType.coneType
val smartcastScope = smartcastType.scope( val smartcastScope = smartcastType.scope(
useSiteSession, useSiteSession = useSiteSession,
scopeSession, scopeSession = scopeSession,
FakeOverrideTypeCalculator.DoNothing, fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredPhase = FirResolvePhase.STATUS requiredMembersPhase = requiredMembersPhase,
) )
if (isStable) { if (isStable) {
return smartcastScope return smartcastScope
} }
val originalScope = originalExpression.typeRef.coneType
.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase) val originalScope = originalExpression.typeRef.coneType.scope(
?: return smartcastScope useSiteSession = useSiteSession,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = requiredMembersPhase,
) ?: return smartcastScope
if (smartcastScope == null) { if (smartcastScope == null) {
return originalScope return originalScope
@@ -62,60 +66,58 @@ fun ConeKotlinType.scope(
useSiteSession: FirSession, useSiteSession: FirSession,
scopeSession: ScopeSession, scopeSession: ScopeSession,
fakeOverrideTypeCalculator: FakeOverrideTypeCalculator, fakeOverrideTypeCalculator: FakeOverrideTypeCalculator,
requiredPhase: FirResolvePhase?, requiredMembersPhase: FirResolvePhase?,
): FirTypeScope? { ): FirTypeScope? {
val scope = scope(useSiteSession, scopeSession, requiredPhase) ?: return null val scope = scope(useSiteSession, scopeSession, requiredMembersPhase) ?: return null
if (fakeOverrideTypeCalculator == FakeOverrideTypeCalculator.DoNothing) return scope if (fakeOverrideTypeCalculator == FakeOverrideTypeCalculator.DoNothing) return scope
return FirScopeWithFakeOverrideTypeCalculator(scope, fakeOverrideTypeCalculator) return FirScopeWithFakeOverrideTypeCalculator(scope, fakeOverrideTypeCalculator)
} }
private fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession, requiredPhase: FirResolvePhase?): FirTypeScope? { private fun ConeKotlinType.scope(
return when (this) { useSiteSession: FirSession,
is ConeErrorType -> null scopeSession: ScopeSession,
is ConeClassLikeType -> classScope(useSiteSession, scopeSession, requiredPhase, lookupTag) requiredMembersPhase: FirResolvePhase?,
is ConeTypeParameterType -> { ): FirTypeScope? = when (this) {
val symbol = lookupTag.symbol is ConeErrorType -> null
scopeSession.getOrBuild(symbol, TYPE_PARAMETER_SCOPE_KEY) { is ConeClassLikeType -> classScope(useSiteSession, scopeSession, requiredMembersPhase, lookupTag)
val intersectionType = ConeTypeIntersector.intersectTypes( is ConeTypeParameterType -> {
useSiteSession.typeContext, val symbol = lookupTag.symbol
symbol.resolvedBounds.map { it.coneType } scopeSession.getOrBuild(symbol, TYPE_PARAMETER_SCOPE_KEY) {
) val intersectionType = ConeTypeIntersector.intersectTypes(
intersectionType.scope(useSiteSession, scopeSession, requiredPhase) ?: FirTypeScope.Empty useSiteSession.typeContext,
} symbol.resolvedBounds.map { it.coneType }
)
intersectionType.scope(useSiteSession, scopeSession, requiredMembersPhase) ?: FirTypeScope.Empty
} }
is ConeRawType -> lowerBound.scope(useSiteSession, scopeSession, requiredPhase)
is ConeDynamicType -> useSiteSession.dynamicMembersStorage.getDynamicScopeFor(scopeSession)
is ConeFlexibleType -> lowerBound.scope(useSiteSession, scopeSession, requiredPhase)
is ConeIntersectionType -> FirTypeIntersectionScope.prepareIntersectionScope(
useSiteSession,
FirIntersectionScopeOverrideChecker(useSiteSession),
intersectedTypes.mapNotNullTo(mutableListOf()) {
it.scope(useSiteSession, scopeSession, requiredPhase)
},
this
)
is ConeDefinitelyNotNullType -> original.scope(useSiteSession, scopeSession, requiredPhase)
is ConeIntegerConstantOperatorType -> scopeSession.getOrBuildScopeForIntegerConstantOperatorType(useSiteSession, this)
is ConeIntegerLiteralConstantType -> error("ILT should not be in receiver position")
else -> null
} }
is ConeRawType -> lowerBound.scope(useSiteSession, scopeSession, requiredMembersPhase)
is ConeDynamicType -> useSiteSession.dynamicMembersStorage.getDynamicScopeFor(scopeSession)
is ConeFlexibleType -> lowerBound.scope(useSiteSession, scopeSession, requiredMembersPhase)
is ConeIntersectionType -> FirTypeIntersectionScope.prepareIntersectionScope(
useSiteSession,
FirIntersectionScopeOverrideChecker(useSiteSession),
intersectedTypes.mapNotNullTo(mutableListOf()) {
it.scope(useSiteSession, scopeSession, requiredMembersPhase)
},
this
)
is ConeDefinitelyNotNullType -> original.scope(useSiteSession, scopeSession, requiredMembersPhase)
is ConeIntegerConstantOperatorType -> scopeSession.getOrBuildScopeForIntegerConstantOperatorType(useSiteSession, this)
is ConeIntegerLiteralConstantType -> error("ILT should not be in receiver position")
else -> null
} }
private fun ConeClassLikeType.classScope( private fun ConeClassLikeType.classScope(
useSiteSession: FirSession, useSiteSession: FirSession,
scopeSession: ScopeSession, scopeSession: ScopeSession,
requiredPhase: FirResolvePhase?, requiredMembersPhase: FirResolvePhase?,
memberOwnerLookupTag: ConeClassLikeLookupTag memberOwnerLookupTag: ConeClassLikeLookupTag
): FirTypeScope? { ): FirTypeScope? {
val fullyExpandedType = fullyExpandedType(useSiteSession) val fullyExpandedType = fullyExpandedType(useSiteSession)
val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null
if (requiredPhase != null) {
fir.symbol.lazyResolveToPhase(requiredPhase)
}
val substitutor = when { val substitutor = when {
attributes.contains(CompilerConeAttributes.RawType) -> ConeRawScopeSubstitutor(useSiteSession) attributes.contains(CompilerConeAttributes.RawType) -> ConeRawScopeSubstitutor(useSiteSession)
else -> substitutorByMap( else -> substitutorByMap(
@@ -124,14 +126,7 @@ private fun ConeClassLikeType.classScope(
) )
} }
return fir.scopeForClass(substitutor, useSiteSession, scopeSession, memberOwnerLookupTag, requiredPhase) return fir.scopeForClass(substitutor, useSiteSession, scopeSession, memberOwnerLookupTag, requiredMembersPhase)
}
private fun ConeClassLikeType.obtainFirOfClass(useSiteSession: FirSession, requiredPhase: FirResolvePhase): FirClass? {
val fullyExpandedType = fullyExpandedType(useSiteSession)
val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null
return fir.also { it.symbol.lazyResolveToPhase(requiredPhase) }
} }
fun FirClassSymbol<*>.defaultType(): ConeClassLikeType = fir.defaultType() fun FirClassSymbol<*>.defaultType(): ConeClassLikeType = fir.defaultType()
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -39,8 +39,12 @@ interface ReceiverValue : Receiver {
val receiverExpression: FirExpression val receiverExpression: FirExpression
fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = type.scope(
type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) useSiteSession = useSiteSession,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)
} }
// TODO: should inherit just Receiver, not ReceiverValue // TODO: should inherit just Receiver, not ReceiverValue
@@ -68,10 +72,21 @@ open class ExpressionReceiverValue(
if (receiverExpr is FirCheckNotNullCall) { if (receiverExpr is FirCheckNotNullCall) {
receiverExpr = receiverExpr.arguments.firstOrNull() receiverExpr = receiverExpr.arguments.firstOrNull()
} }
if (receiverExpr is FirSmartCastExpression) { if (receiverExpr is FirSmartCastExpression) {
return receiverExpr.smartcastScope(useSiteSession, scopeSession, requiredPhase = FirResolvePhase.STATUS) return receiverExpr.smartcastScope(
useSiteSession,
scopeSession,
requiredMembersPhase = FirResolvePhase.STATUS,
)
} }
return type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS)
return type.scope(
useSiteSession,
scopeSession,
FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)
} }
} }
@@ -93,7 +108,12 @@ sealed class ImplicitReceiverValue<S : FirBasedSymbol<*>>(
val expandedType: ConeKotlinType = type.applyIf(type is ConeClassLikeType) { fullyExpandedType(useSiteSession) } val expandedType: ConeKotlinType = type.applyIf(type is ConeClassLikeType) { fullyExpandedType(useSiteSession) }
var implicitScope: FirTypeScope? = var implicitScope: FirTypeScope? =
type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) type.scope(
useSiteSession,
scopeSession,
FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS
)
private set private set
override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = implicitScope override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = implicitScope
@@ -109,8 +129,12 @@ sealed class ImplicitReceiverValue<S : FirBasedSymbol<*>>(
fun updateTypeInBuilderInference(type: ConeKotlinType) { fun updateTypeInBuilderInference(type: ConeKotlinType) {
this.type = type this.type = type
receiverExpression = receiverExpression(boundSymbol, type, contextReceiverNumber) receiverExpression = receiverExpression(boundSymbol, type, contextReceiverNumber)
implicitScope = implicitScope = type.scope(
type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) useSiteSession = useSiteSession,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)
} }
/* /*
@@ -136,8 +160,13 @@ sealed class ImplicitReceiverValue<S : FirBasedSymbol<*>>(
typeRef = smartcastType.copyWithNewSourceKind(KtFakeSourceElementKind.ImplicitTypeRef) typeRef = smartcastType.copyWithNewSourceKind(KtFakeSourceElementKind.ImplicitTypeRef)
} }
} }
implicitScope =
type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) implicitScope = type.scope(
useSiteSession = useSiteSession,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)
} }
abstract fun createSnapshot(): ImplicitReceiverValue<S> abstract fun createSnapshot(): ImplicitReceiverValue<S>
@@ -39,6 +39,10 @@ class FirKotlinScopeProvider(
scopeSession: ScopeSession, scopeSession: ScopeSession,
memberRequiredPhase: FirResolvePhase?, memberRequiredPhase: FirResolvePhase?,
): FirTypeScope { ): FirTypeScope {
memberRequiredPhase?.let {
klass.lazyResolveToPhaseWithCallableMembers(it)
}
return scopeSession.getOrBuild(klass.symbol, USE_SITE) { return scopeSession.getOrBuild(klass.symbol, USE_SITE) {
val declaredScope = useSiteSession.declaredMemberScope(klass) val declaredScope = useSiteSession.declaredMemberScope(klass)
@@ -173,10 +177,6 @@ private fun FirClass.scopeForClassImpl(
memberOwnerLookupTag: ConeClassLikeLookupTag?, memberOwnerLookupTag: ConeClassLikeLookupTag?,
memberRequiredPhase: FirResolvePhase?, memberRequiredPhase: FirResolvePhase?,
): FirTypeScope { ): FirTypeScope {
memberRequiredPhase?.let {
lazyResolveToPhaseWithCallableMembers(it)
}
val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase) val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase)
if (substitutor == ConeSubstitutor.Empty) return basicScope if (substitutor == ConeSubstitutor.Empty) return basicScope
@@ -29,8 +29,9 @@ fun debugCollectOverrides(symbol: FirCallableSymbol<*>, session: FirSession, sco
session, session,
scopeSession, scopeSession,
FakeOverrideTypeCalculator.DoNothing, FakeOverrideTypeCalculator.DoNothing,
requiredPhase = FirResolvePhase.STATUS requiredMembersPhase = FirResolvePhase.STATUS,
) ?: return emptyMap() ) ?: return emptyMap()
return debugCollectOverrides(symbol, scope) return debugCollectOverrides(symbol, scope)
} }
@@ -54,7 +54,7 @@ class FirDelegatedMemberScope(
session, session,
scopeSession, scopeSession,
FakeOverrideTypeCalculator.DoNothing, FakeOverrideTypeCalculator.DoNothing,
requiredPhase = null, requiredMembersPhase = null,
) )
private fun collectFunctionsFromSpecificField( private fun collectFunctionsFromSpecificField(
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -62,7 +62,12 @@ class FirDynamicScope @FirDynamicScopeConstructor constructor(
override fun getClassifierNames(): Set<Name> = emptySet() override fun getClassifierNames(): Set<Name> = emptySet()
private val anyTypeScope by lazy { private val anyTypeScope by lazy {
session.builtinTypes.anyType.type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = null) session.builtinTypes.anyType.type.scope(
session,
scopeSession,
FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = null,
)
} }
override fun processFunctionsByName( override fun processFunctionsByName(
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -35,8 +35,13 @@ class FirIntegerConstantOperatorScope(
true -> session.builtinTypes.uIntType true -> session.builtinTypes.uIntType
false -> session.builtinTypes.intType false -> session.builtinTypes.intType
}.type }.type
baseType.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = null)
?: error("Scope for $baseType not found") baseType.scope(
session,
scopeSession,
FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = null,
) ?: error("Scope for $baseType not found")
} }
private val mappedFunctions = mutableMapOf<Name, FirNamedFunctionSymbol>() private val mappedFunctions = mutableMapOf<Name, FirNamedFunctionSymbol>()
@@ -203,7 +203,14 @@ fun ConeKotlinType.findContributedInvokeSymbol(
} else { } else {
FakeOverrideTypeCalculator.DoNothing FakeOverrideTypeCalculator.DoNothing
} }
val scope = scope(session, scopeSession, fakeOverrideTypeCalculator, requiredPhase = FirResolvePhase.STATUS) ?: return null
val scope = scope(
useSiteSession = session,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = fakeOverrideTypeCalculator,
requiredMembersPhase = FirResolvePhase.STATUS,
) ?: return null
var declaredInvoke: FirNamedFunctionSymbol? = null var declaredInvoke: FirNamedFunctionSymbol? = null
scope.processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol -> scope.processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol ->
if (functionSymbol.fir.valueParameters.size == baseInvokeSymbol.fir.valueParameters.size) { if (functionSymbol.fir.valueParameters.size == baseInvokeSymbol.fir.valueParameters.size) {
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -176,8 +176,13 @@ private fun BodyResolveComponents.getCallableReferenceAdaptation(
if (expectedArgumentsCount < 0) return null if (expectedArgumentsCount < 0) return null
val fakeArguments = createFakeArgumentsForReference(function, expectedArgumentsCount, inputTypes, unboundReceiverCount) val fakeArguments = createFakeArgumentsForReference(function, expectedArgumentsCount, inputTypes, unboundReceiverCount)
val originScope = function.dispatchReceiverType val originScope = function.dispatchReceiverType?.scope(
?.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) useSiteSession = session,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)
val argumentMapping = mapArguments(fakeArguments, function, originScope = originScope, callSiteIsOperatorCall = false) val argumentMapping = mapArguments(fakeArguments, function, originScope = originScope, callSiteIsOperatorCall = false)
if (argumentMapping.diagnostics.any { !it.applicability.isSuccess }) return null if (argumentMapping.diagnostics.any { !it.applicability.isSuccess }) return null
@@ -180,7 +180,7 @@ private fun processConstructors(
session, session,
bodyResolveComponents.scopeSession, bodyResolveComponents.scopeSession,
FakeOverrideTypeCalculator.DoNothing, FakeOverrideTypeCalculator.DoNothing,
requiredPhase = FirResolvePhase.STATUS requiredMembersPhase = FirResolvePhase.STATUS,
) )
val outerType = bodyResolveComponents.outerClassManager.outerType(type) val outerType = bodyResolveComponents.outerClassManager.outerType(type)
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -129,14 +129,22 @@ private inline fun BodyResolveComponents.resolveSupertypesByMembers(
private fun BodyResolveComponents.getFunctionMembers(type: ConeKotlinType, name: Name): Collection<FirCallableDeclaration> = private fun BodyResolveComponents.getFunctionMembers(type: ConeKotlinType, name: Name): Collection<FirCallableDeclaration> =
buildList { buildList {
type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) type.scope(
?.processFunctionsByName(name) { add(it.fir) } useSiteSession = session,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)?.processFunctionsByName(name) { add(it.fir) }
} }
private fun BodyResolveComponents.getPropertyMembers(type: ConeKotlinType, name: Name): Collection<FirCallableDeclaration> = private fun BodyResolveComponents.getPropertyMembers(type: ConeKotlinType, name: Name): Collection<FirCallableDeclaration> =
buildList { buildList {
type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) type.scope(
?.processPropertiesByName(name) { addIfNotNull(it.fir as? FirVariable) } useSiteSession = session,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)?.processPropertiesByName(name) { addIfNotNull(it.fir as? FirVariable) }
} }
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -93,8 +93,9 @@ class MemberScopeTowerLevel(
session, session,
scopeSession, scopeSession,
bodyResolveComponents.returnTypeCalculator.fakeOverrideTypeCalculator, bodyResolveComponents.returnTypeCalculator.fakeOverrideTypeCalculator,
requiredPhase = FirResolvePhase.STATUS requiredMembersPhase = FirResolvePhase.STATUS,
) )
if (scopeWithoutSmartcast == null) { if (scopeWithoutSmartcast == null) {
consumeCandidates(output, candidates) consumeCandidates(output, candidates)
} else { } else {
@@ -133,14 +134,12 @@ class MemberScopeTowerLevel(
// So, here we decide to preserve the K1 behavior just by converting the type to its non-raw version // So, here we decide to preserve the K1 behavior just by converting the type to its non-raw version
if (dispatchReceiverType.isRaw()) { if (dispatchReceiverType.isRaw()) {
typeForSyntheticScope = dispatchReceiverType.convertToNonRawVersion() typeForSyntheticScope = dispatchReceiverType.convertToNonRawVersion()
useSiteForSyntheticScope = useSiteForSyntheticScope = typeForSyntheticScope.scope(
typeForSyntheticScope.scope( session,
session, scopeSession,
scopeSession, FakeOverrideTypeCalculator.DoNothing,
FakeOverrideTypeCalculator.DoNothing, requiredMembersPhase = FirResolvePhase.STATUS,
requiredPhase = FirResolvePhase.STATUS ) ?: error("No scope for flexible type scope, while it's not null for $dispatchReceiverType")
)
?: error("No scope for flexible type scope, while it's not null for $dispatchReceiverType")
} else { } else {
typeForSyntheticScope = dispatchReceiverType typeForSyntheticScope = dispatchReceiverType
useSiteForSyntheticScope = scope useSiteForSyntheticScope = scope
@@ -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. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -48,12 +48,16 @@ class IntegerLiteralAndOperatorApproximationTransformer(
private val TO_U_LONG = Name.identifier("toULong") private val TO_U_LONG = Name.identifier("toULong")
} }
private val toLongSymbol by lazy { findConversionFunction(session.builtinTypes.intType, TO_LONG)} private val toLongSymbol by lazy { findConversionFunction(session.builtinTypes.intType, TO_LONG) }
private val toULongSymbol by lazy { findConversionFunction(session.builtinTypes.uIntType, TO_U_LONG)} private val toULongSymbol by lazy { findConversionFunction(session.builtinTypes.uIntType, TO_U_LONG) }
private fun findConversionFunction(receiverType: FirImplicitBuiltinTypeRef, name: Name): FirNamedFunctionSymbol { private fun findConversionFunction(receiverType: FirImplicitBuiltinTypeRef, name: Name): FirNamedFunctionSymbol {
return receiverType.type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS)!! return receiverType.type.scope(
.getFunctions(name).single() useSiteSession = session,
scopeSession = scopeSession,
fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
)!!.getFunctions(name).single()
} }
override fun <E : FirElement> transformElement(element: E, data: ConeKotlinType?): E { override fun <E : FirElement> transformElement(element: E, data: ConeKotlinType?): E {
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.descriptors.isEnumClass import org.jetbrains.kotlin.descriptors.isEnumClass
import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.utils.*
import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride
import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
@@ -143,13 +142,19 @@ class FirExpectActualMatchingContext(
true -> actualSession true -> actualSession
false -> symbol.moduleData.session false -> symbol.moduleData.session
} }
val scope = symbol.defaultType()
.scope(useSiteSession = session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) val scope = symbol.defaultType().scope(
?: return emptyList() useSiteSession = session,
scopeSession,
FakeOverrideTypeCalculator.DoNothing,
requiredMembersPhase = FirResolvePhase.STATUS,
) ?: return emptyList()
return mutableListOf<FirBasedSymbol<*>>().apply { return mutableListOf<FirBasedSymbol<*>>().apply {
for (name in scope.getCallableNames()) { for (name in scope.getCallableNames()) {
scope.getMembersTo(this, name) scope.getMembersTo(this, name)
} }
// TODO: replace with scope lookup // TODO: replace with scope lookup
for (name in symbol.declarationSymbols.mapNotNull { (it as? FirRegularClassSymbol)?.classId?.shortClassName }) { for (name in symbol.declarationSymbols.mapNotNull { (it as? FirRegularClassSymbol)?.classId?.shortClassName }) {
addIfNotNull(scope.getSingleClassifier(name) as? FirRegularClassSymbol) addIfNotNull(scope.getSingleClassifier(name) as? FirRegularClassSymbol)
@@ -160,14 +165,13 @@ class FirExpectActualMatchingContext(
override fun RegularClassSymbolMarker.getMembersForExpectClass(name: Name): List<FirCallableSymbol<*>> { override fun RegularClassSymbolMarker.getMembersForExpectClass(name: Name): List<FirCallableSymbol<*>> {
val symbol = asSymbol() val symbol = asSymbol()
val scope = symbol.defaultType() val scope = symbol.defaultType().scope(
.scope( useSiteSession = symbol.moduleData.session,
useSiteSession = symbol.moduleData.session, scopeSession,
scopeSession, FakeOverrideTypeCalculator.DoNothing,
FakeOverrideTypeCalculator.DoNothing, requiredMembersPhase = FirResolvePhase.STATUS,
requiredPhase = FirResolvePhase.STATUS ) ?: return emptyList()
)
?: return emptyList()
return mutableListOf<FirCallableSymbol<*>>().apply { return mutableListOf<FirCallableSymbol<*>>().apply {
scope.getMembersTo(this, name) scope.getMembersTo(this, name)
} }