diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt index 806315ab34a..ab3812841c8 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/components/KtFirScopeProvider.kt @@ -279,7 +279,7 @@ internal class KtFirScopeProvider( firResolveSession.useSiteFirSession, getScopeSession(), FakeOverrideTypeCalculator.Forced, - requiredPhase = FirResolvePhase.STATUS, + requiredMembersPhase = FirResolvePhase.STATUS, ) } diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/FirReferenceResolveHelper.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/FirReferenceResolveHelper.kt index 2012473c695..5c38295f39b 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/FirReferenceResolveHelper.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/references/FirReferenceResolveHelper.kt @@ -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. */ @@ -234,8 +234,9 @@ internal object FirReferenceResolveHelper { session, analysisSession.getScopeSessionFor(analysisSession.useSiteSession), FakeOverrideTypeCalculator.DoNothing, - requiredPhase = FirResolvePhase.STATUS + requiredMembersPhase = FirResolvePhase.STATUS, ) ?: return emptyList() + return buildList { scope.processFunctionsByName(OperatorNameConventions.EQUALS) { functionSymbol -> val parameterSymbol = functionSymbol.valueParameterSymbols.singleOrNull() diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt index 07860cc26ce..84e87736282 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/symbols/KtFirPropertySetterSymbol.kt @@ -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. */ @@ -56,8 +56,9 @@ internal class KtFirPropertySetterSymbol( session, analysisSession.getScopeSessionFor(session), FakeOverrideTypeCalculator.DoNothing, - requiredPhase = FirResolvePhase.STATUS, + requiredMembersPhase = FirResolvePhase.STATUS, ) ?: return false + val overriddenProperties = containingClassScope.getDirectOverriddenProperties(propertySymbol) overriddenProperties.any { it.isVar } } diff --git a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt index c06bd239b93..a2095e59c19 100644 --- a/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt +++ b/compiler/fir/fir-deserialization/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt @@ -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. */ @@ -212,13 +212,17 @@ abstract class AbstractAnnotationDeserializer( val symbol = lookupTag.toSymbol(session) val firAnnotationClass = (symbol as? FirRegularClassSymbol)?.fir ?: return@lazy null - val classScope = - firAnnotationClass.defaultType() - .scope(session, ScopeSession(), FakeOverrideTypeCalculator.DoNothing, requiredPhase = null) - ?: error("Null scope for $classId") + val classScope = firAnnotationClass.defaultType().scope( + useSiteSession = session, + scopeSession = ScopeSession(), + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = null, + ) ?: error("Null scope for $classId") - val constructor = - classScope.getDeclaredConstructors().singleOrNull()?.fir ?: error("No single constructor found for $classId") + val constructor = classScope.getDeclaredConstructors() + .singleOrNull() + ?.fir + ?: error("No single constructor found for $classId") constructor.valueParameters.associateBy { it.name } } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index 5b94f8cb37f..c6439910341 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -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.impl.FirClassSymbol 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.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl @@ -28,21 +27,26 @@ import org.jetbrains.kotlin.name.ClassId fun FirSmartCastExpression.smartcastScope( useSiteSession: FirSession, scopeSession: ScopeSession, - requiredPhase: FirResolvePhase? = null, + requiredMembersPhase: FirResolvePhase? = null, ): FirTypeScope? { val smartcastType = smartcastTypeWithoutNullableNothing?.coneType ?: smartcastType.coneType val smartcastScope = smartcastType.scope( - useSiteSession, - scopeSession, - FakeOverrideTypeCalculator.DoNothing, - requiredPhase = FirResolvePhase.STATUS + useSiteSession = useSiteSession, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = requiredMembersPhase, ) + if (isStable) { return smartcastScope } - val originalScope = originalExpression.typeRef.coneType - .scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase) - ?: return smartcastScope + + val originalScope = originalExpression.typeRef.coneType.scope( + useSiteSession = useSiteSession, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = requiredMembersPhase, + ) ?: return smartcastScope if (smartcastScope == null) { return originalScope @@ -62,60 +66,58 @@ fun ConeKotlinType.scope( useSiteSession: FirSession, scopeSession: ScopeSession, fakeOverrideTypeCalculator: FakeOverrideTypeCalculator, - requiredPhase: FirResolvePhase?, + requiredMembersPhase: FirResolvePhase?, ): FirTypeScope? { - val scope = scope(useSiteSession, scopeSession, requiredPhase) ?: return null + val scope = scope(useSiteSession, scopeSession, requiredMembersPhase) ?: return null if (fakeOverrideTypeCalculator == FakeOverrideTypeCalculator.DoNothing) return scope return FirScopeWithFakeOverrideTypeCalculator(scope, fakeOverrideTypeCalculator) } -private fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession, requiredPhase: FirResolvePhase?): FirTypeScope? { - return when (this) { - is ConeErrorType -> null - is ConeClassLikeType -> classScope(useSiteSession, scopeSession, requiredPhase, lookupTag) - is ConeTypeParameterType -> { - val symbol = lookupTag.symbol - scopeSession.getOrBuild(symbol, TYPE_PARAMETER_SCOPE_KEY) { - val intersectionType = ConeTypeIntersector.intersectTypes( - useSiteSession.typeContext, - symbol.resolvedBounds.map { it.coneType } - ) - intersectionType.scope(useSiteSession, scopeSession, requiredPhase) ?: FirTypeScope.Empty - } +private fun ConeKotlinType.scope( + useSiteSession: FirSession, + scopeSession: ScopeSession, + requiredMembersPhase: FirResolvePhase?, +): FirTypeScope? = when (this) { + is ConeErrorType -> null + is ConeClassLikeType -> classScope(useSiteSession, scopeSession, requiredMembersPhase, lookupTag) + is ConeTypeParameterType -> { + val symbol = lookupTag.symbol + scopeSession.getOrBuild(symbol, TYPE_PARAMETER_SCOPE_KEY) { + val intersectionType = ConeTypeIntersector.intersectTypes( + 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( useSiteSession: FirSession, scopeSession: ScopeSession, - requiredPhase: FirResolvePhase?, + requiredMembersPhase: FirResolvePhase?, memberOwnerLookupTag: ConeClassLikeLookupTag ): FirTypeScope? { val fullyExpandedType = fullyExpandedType(useSiteSession) val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null - - if (requiredPhase != null) { - fir.symbol.lazyResolveToPhase(requiredPhase) - } - val substitutor = when { attributes.contains(CompilerConeAttributes.RawType) -> ConeRawScopeSubstitutor(useSiteSession) else -> substitutorByMap( @@ -124,14 +126,7 @@ private fun ConeClassLikeType.classScope( ) } - return fir.scopeForClass(substitutor, useSiteSession, scopeSession, memberOwnerLookupTag, requiredPhase) -} - -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) } + return fir.scopeForClass(substitutor, useSiteSession, scopeSession, memberOwnerLookupTag, requiredMembersPhase) } fun FirClassSymbol<*>.defaultType(): ConeClassLikeType = fir.defaultType() diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt index b8a11d8f8f9..5d5e8c4cd45 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt @@ -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. */ @@ -39,8 +39,12 @@ interface ReceiverValue : Receiver { val receiverExpression: FirExpression - fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = - type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) + fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = type.scope( + useSiteSession = useSiteSession, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + ) } // TODO: should inherit just Receiver, not ReceiverValue @@ -68,10 +72,21 @@ open class ExpressionReceiverValue( if (receiverExpr is FirCheckNotNullCall) { receiverExpr = receiverExpr.arguments.firstOrNull() } + 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>( val expandedType: ConeKotlinType = type.applyIf(type is ConeClassLikeType) { fullyExpandedType(useSiteSession) } var implicitScope: FirTypeScope? = - type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) + type.scope( + useSiteSession, + scopeSession, + FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS + ) private set override fun scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? = implicitScope @@ -109,8 +129,12 @@ sealed class ImplicitReceiverValue>( fun updateTypeInBuilderInference(type: ConeKotlinType) { this.type = type receiverExpression = receiverExpression(boundSymbol, type, contextReceiverNumber) - implicitScope = - type.scope(useSiteSession, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) + implicitScope = type.scope( + useSiteSession = useSiteSession, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + ) } /* @@ -136,8 +160,13 @@ sealed class ImplicitReceiverValue>( 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 diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt index dd32065dd2d..61e13bd12ac 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt @@ -39,6 +39,10 @@ class FirKotlinScopeProvider( scopeSession: ScopeSession, memberRequiredPhase: FirResolvePhase?, ): FirTypeScope { + memberRequiredPhase?.let { + klass.lazyResolveToPhaseWithCallableMembers(it) + } + return scopeSession.getOrBuild(klass.symbol, USE_SITE) { val declaredScope = useSiteSession.declaredMemberScope(klass) @@ -173,10 +177,6 @@ private fun FirClass.scopeForClassImpl( memberOwnerLookupTag: ConeClassLikeLookupTag?, memberRequiredPhase: FirResolvePhase?, ): FirTypeScope { - memberRequiredPhase?.let { - lazyResolveToPhaseWithCallableMembers(it) - } - val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false, memberRequiredPhase) if (substitutor == ConeSubstitutor.Empty) return basicScope diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt index c388026b07a..02f39f6b85f 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt @@ -29,8 +29,9 @@ fun debugCollectOverrides(symbol: FirCallableSymbol<*>, session: FirSession, sco session, scopeSession, FakeOverrideTypeCalculator.DoNothing, - requiredPhase = FirResolvePhase.STATUS + requiredMembersPhase = FirResolvePhase.STATUS, ) ?: return emptyMap() + return debugCollectOverrides(symbol, scope) } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt index ad1ca7b1a74..a0231100fb9 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt @@ -54,7 +54,7 @@ class FirDelegatedMemberScope( session, scopeSession, FakeOverrideTypeCalculator.DoNothing, - requiredPhase = null, + requiredMembersPhase = null, ) private fun collectFunctionsFromSpecificField( diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDynamicScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDynamicScope.kt index ba31e295f48..2f03fa815d1 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDynamicScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDynamicScope.kt @@ -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. */ @@ -62,7 +62,12 @@ class FirDynamicScope @FirDynamicScopeConstructor constructor( override fun getClassifierNames(): Set = emptySet() 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( diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerConstantOperatorScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerConstantOperatorScope.kt index 77948d1e6a1..05013dffd38 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerConstantOperatorScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirIntegerConstantOperatorScope.kt @@ -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. */ @@ -35,8 +35,13 @@ class FirIntegerConstantOperatorScope( true -> session.builtinTypes.uIntType false -> session.builtinTypes.intType }.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() diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt index da1911075dd..0c90df9c74d 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/FunctionalTypeUtils.kt @@ -203,7 +203,14 @@ fun ConeKotlinType.findContributedInvokeSymbol( } else { 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 scope.processFunctionsByName(OperatorNameConventions.INVOKE) { functionSymbol -> if (functionSymbol.fir.valueParameters.size == baseInvokeSymbol.fir.valueParameters.size) { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt index 641af5dbc55..836616025be 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt @@ -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. */ @@ -176,8 +176,13 @@ private fun BodyResolveComponents.getCallableReferenceAdaptation( if (expectedArgumentsCount < 0) return null val fakeArguments = createFakeArgumentsForReference(function, expectedArgumentsCount, inputTypes, unboundReceiverCount) - val originScope = function.dispatchReceiverType - ?.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) + val originScope = function.dispatchReceiverType?.scope( + useSiteSession = session, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + ) + val argumentMapping = mapArguments(fakeArguments, function, originScope = originScope, callSiteIsOperatorCall = false) if (argumentMapping.diagnostics.any { !it.applicability.isSuccess }) return null diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt index 1407716a81e..da9ef52a998 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt @@ -180,7 +180,7 @@ private fun processConstructors( session, bodyResolveComponents.scopeSession, FakeOverrideTypeCalculator.DoNothing, - requiredPhase = FirResolvePhase.STATUS + requiredMembersPhase = FirResolvePhase.STATUS, ) val outerType = bodyResolveComponents.outerClassManager.outerType(type) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt index 7d97191c834..348543289c7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/SuperCalls.kt @@ -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. */ @@ -129,14 +129,22 @@ private inline fun BodyResolveComponents.resolveSupertypesByMembers( private fun BodyResolveComponents.getFunctionMembers(type: ConeKotlinType, name: Name): Collection = buildList { - type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) - ?.processFunctionsByName(name) { add(it.fir) } + type.scope( + useSiteSession = session, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + )?.processFunctionsByName(name) { add(it.fir) } } private fun BodyResolveComponents.getPropertyMembers(type: ConeKotlinType, name: Name): Collection = buildList { - type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) - ?.processPropertiesByName(name) { addIfNotNull(it.fir as? FirVariable) } + type.scope( + useSiteSession = session, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + )?.processPropertiesByName(name) { addIfNotNull(it.fir as? FirVariable) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt index 2d3b79e0c38..d0b57d4dc7c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevels.kt @@ -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. */ @@ -93,8 +93,9 @@ class MemberScopeTowerLevel( session, scopeSession, bodyResolveComponents.returnTypeCalculator.fakeOverrideTypeCalculator, - requiredPhase = FirResolvePhase.STATUS + requiredMembersPhase = FirResolvePhase.STATUS, ) + if (scopeWithoutSmartcast == null) { consumeCandidates(output, candidates) } 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 if (dispatchReceiverType.isRaw()) { typeForSyntheticScope = dispatchReceiverType.convertToNonRawVersion() - useSiteForSyntheticScope = - typeForSyntheticScope.scope( - session, - scopeSession, - FakeOverrideTypeCalculator.DoNothing, - requiredPhase = FirResolvePhase.STATUS - ) - ?: error("No scope for flexible type scope, while it's not null for $dispatchReceiverType") + useSiteForSyntheticScope = typeForSyntheticScope.scope( + session, + scopeSession, + FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + ) ?: error("No scope for flexible type scope, while it's not null for $dispatchReceiverType") } else { typeForSyntheticScope = dispatchReceiverType useSiteForSyntheticScope = scope diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralAndOperatorApproximationTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralAndOperatorApproximationTransformer.kt index 19a4b158d96..e51bccf8302 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralAndOperatorApproximationTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralAndOperatorApproximationTransformer.kt @@ -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. */ @@ -48,12 +48,16 @@ class IntegerLiteralAndOperatorApproximationTransformer( private val TO_U_LONG = Name.identifier("toULong") } - 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 toLongSymbol by lazy { findConversionFunction(session.builtinTypes.intType, TO_LONG) } + private val toULongSymbol by lazy { findConversionFunction(session.builtinTypes.uIntType, TO_U_LONG) } private fun findConversionFunction(receiverType: FirImplicitBuiltinTypeRef, name: Name): FirNamedFunctionSymbol { - return receiverType.type.scope(session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS)!! - .getFunctions(name).single() + return receiverType.type.scope( + useSiteSession = session, + scopeSession = scopeSession, + fakeOverrideTypeCalculator = FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + )!!.getFunctions(name).single() } override fun transformElement(element: E, data: ConeKotlinType?): E { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContext.kt index 40c94482855..1a54130b6ad 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContext.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.isEnumClass import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* -import org.jetbrains.kotlin.fir.declarations.utils.* import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor @@ -143,13 +142,19 @@ class FirExpectActualMatchingContext( true -> actualSession false -> symbol.moduleData.session } - val scope = symbol.defaultType() - .scope(useSiteSession = session, scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.STATUS) - ?: return emptyList() + + val scope = symbol.defaultType().scope( + useSiteSession = session, + scopeSession, + FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + ) ?: return emptyList() + return mutableListOf>().apply { for (name in scope.getCallableNames()) { scope.getMembersTo(this, name) } + // TODO: replace with scope lookup for (name in symbol.declarationSymbols.mapNotNull { (it as? FirRegularClassSymbol)?.classId?.shortClassName }) { addIfNotNull(scope.getSingleClassifier(name) as? FirRegularClassSymbol) @@ -160,14 +165,13 @@ class FirExpectActualMatchingContext( override fun RegularClassSymbolMarker.getMembersForExpectClass(name: Name): List> { val symbol = asSymbol() - val scope = symbol.defaultType() - .scope( - useSiteSession = symbol.moduleData.session, - scopeSession, - FakeOverrideTypeCalculator.DoNothing, - requiredPhase = FirResolvePhase.STATUS - ) - ?: return emptyList() + val scope = symbol.defaultType().scope( + useSiteSession = symbol.moduleData.session, + scopeSession, + FakeOverrideTypeCalculator.DoNothing, + requiredMembersPhase = FirResolvePhase.STATUS, + ) ?: return emptyList() + return mutableListOf>().apply { scope.getMembersTo(this, name) }