diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker.kt index 3d980b9fc39..8296c4aa937 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker.kt @@ -83,7 +83,6 @@ internal object FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker : Fir ): FirNamedFunctionSymbol? { val potentialExpects = findPotentialExpectClassMembersForActual( expectSymbol, actualSymbol, actualMember, - checkClassScopesCompatibility = false ) val expectMember: DeclarationSymbolMarker = potentialExpects.entries .singleOrNull { it.value == ExpectActualMatchingCompatibility.MatchedSuccessfully }?.key diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt index db12c422b41..b3c218342df 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirExpectActualDeclarationChecker.kt @@ -242,7 +242,6 @@ object FirExpectActualDeclarationChecker : FirBasicDeclarationChecker() { AbstractExpectActualChecker.getClassifiersCompatibility( expectSymbol, actualSymbol, - checkClassScopesCompatibility = true, context, ) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt index 77d9722f046..663fe774a35 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/mpp/FirExpectActualMatchingContextImpl.kt @@ -523,7 +523,6 @@ class FirExpectActualMatchingContextImpl private constructor( expectClass: RegularClassSymbolMarker, actualClass: RegularClassSymbolMarker, actualMember: DeclarationSymbolMarker, - checkClassScopesCompatibility: Boolean, ): Map, ExpectActualMatchingCompatibility> { val mapping = actualClass.asSymbol().fir.memberExpectForActual return mapping?.get(actualMember to expectClass) ?: emptyMap() diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt index 8706bbb7724..e48ae6571e1 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/actualizer/ExpectActualCollector.kt @@ -234,7 +234,6 @@ private class ExpectActualLinkCollector : IrElementVisitor = error("Should not be called") // It's a stub, because not needed anywhere diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualAnnotationMatchChecker.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualAnnotationMatchChecker.kt index 9843fced9a9..d83e4c2d6e8 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualAnnotationMatchChecker.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualAnnotationMatchChecker.kt @@ -310,11 +310,6 @@ object AbstractExpectActualAnnotationMatchChecker { } val expectToCompatibilityMap = findPotentialExpectClassMembersForActual( expectClass, actualClass, actualMember, - // Optimization: don't check class scopes, because: - // 1. Annotation checker runs no matter if found expect class is compatible or not. - // 2. Class always has at most one corresponding `expect` class (unlike for functions, which may have several overrides), - // so we are sure that we found the right member. - checkClassScopesCompatibility = false, ) val expectMember = expectToCompatibilityMap .filter { it.value == ExpectActualMatchingCompatibility.MatchedSuccessfully }.keys.singleOrNull() diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualChecker.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualChecker.kt index 445aae5ae9b..e420b30ca4f 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualChecker.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualChecker.kt @@ -33,7 +33,6 @@ object AbstractExpectActualChecker { fun getClassifiersCompatibility( expectClassSymbol: RegularClassSymbolMarker, actualClassLikeSymbol: ClassLikeSymbolMarker, - checkClassScopesCompatibility: Boolean, context: ExpectActualMatchingContext, ): ExpectActualCheckingCompatibility { val result = with(context) { @@ -41,7 +40,6 @@ object AbstractExpectActualChecker { expectClassSymbol, actualClassLikeSymbol, parentSubstitutor = null, - checkClassScopesCompatibility, ) } @Suppress("UNCHECKED_CAST") @@ -74,7 +72,6 @@ object AbstractExpectActualChecker { expectDeclaration: DeclarationSymbolMarker, actualDeclarations: List, context: ExpectActualMatchingContext, - checkClassScopesCompatibility: Boolean, ) { with(context) { checkSingleExpectAgainstPotentialActuals( @@ -84,7 +81,6 @@ object AbstractExpectActualChecker { expectClassSymbol = null, actualClassSymbol = null, incompatibleMembers = null, - checkClassScopesCompatibility = checkClassScopesCompatibility, ) } } @@ -95,12 +91,10 @@ object AbstractExpectActualChecker { expectClassSymbol: RegularClassSymbolMarker, actualClassLikeSymbol: ClassLikeSymbolMarker, parentSubstitutor: TypeSubstitutorMarker?, - checkClassScopes: Boolean, ): ExpectActualCheckingCompatibility<*> = getClassifiersIncompatibility( expectClassSymbol, actualClassLikeSymbol, parentSubstitutor, - checkClassScopes, ) ?: ExpectActualCheckingCompatibility.Compatible @@ -110,7 +104,6 @@ object AbstractExpectActualChecker { expectClassSymbol: RegularClassSymbolMarker, actualClassLikeSymbol: ClassLikeSymbolMarker, parentSubstitutor: TypeSubstitutorMarker?, - checkClassScopesCompatibility: Boolean, ): ExpectActualCheckingCompatibility.Incompatible<*>? { // Can't check FQ names here because nested expected class may be implemented via actual typealias's expansion with the other FQ name require(expectClassSymbol.name == actualClassLikeSymbol.name) { @@ -165,9 +158,7 @@ object AbstractExpectActualChecker { return ExpectActualCheckingCompatibility.Supertypes } - if (checkClassScopesCompatibility) { - getClassScopesIncompatibility(expectClassSymbol, actualClass, substitutor)?.let { return it } - } + getClassScopesIncompatibility(expectClassSymbol, actualClass, substitutor)?.let { return it } return null } @@ -256,7 +247,6 @@ object AbstractExpectActualChecker { expectClassSymbol, actualClassSymbol, incompatibleMembers, - checkClassScopesCompatibility = true, ) } } @@ -284,7 +274,6 @@ object AbstractExpectActualChecker { expectClassSymbol: RegularClassSymbolMarker?, actualClassSymbol: RegularClassSymbolMarker?, incompatibleMembers: MutableList, List>>>?, - checkClassScopesCompatibility: Boolean, ) { val mapping = actualMembers.keysToMap { actualMember -> when (expectMember) { @@ -302,7 +291,6 @@ object AbstractExpectActualChecker { expectMember, actualMember as ClassLikeSymbolMarker, parentSubstitutor, - checkClassScopesCompatibility, ) } else -> error("Unsupported declaration: $expectMember ($actualMembers)") @@ -360,62 +348,6 @@ object AbstractExpectActualChecker { ) ?: ExpectActualCheckingCompatibility.Compatible } - context(ExpectActualMatchingContext<*>) - private fun getCallablesStrongIncompatibility( - expectDeclaration: CallableSymbolMarker, - actualDeclaration: CallableSymbolMarker, - insideAnnotationClass: Boolean, - parentSubstitutor: TypeSubstitutorMarker?, - ): ExpectActualMatchingCompatibility.Mismatch? { - if (expectDeclaration is FunctionSymbolMarker != actualDeclaration is FunctionSymbolMarker) { - return ExpectActualMatchingCompatibility.CallableKind - } - - val expectedReceiverType = expectDeclaration.extensionReceiverType - val actualReceiverType = actualDeclaration.extensionReceiverType - if ((expectedReceiverType != null) != (actualReceiverType != null)) { - return ExpectActualMatchingCompatibility.ParameterShape - } - - val expectedValueParameters = expectDeclaration.valueParameters - val actualValueParameters = actualDeclaration.valueParameters - if (!valueParametersCountCompatible(expectDeclaration, actualDeclaration, expectedValueParameters, actualValueParameters)) { - return ExpectActualMatchingCompatibility.ParameterCount - } - - val expectedTypeParameters = expectDeclaration.typeParameters - val actualTypeParameters = actualDeclaration.typeParameters - if (expectedTypeParameters.size != actualTypeParameters.size) { - return ExpectActualMatchingCompatibility.FunctionTypeParameterCount - } - - val substitutor = createExpectActualTypeParameterSubstitutor( - (expectedTypeParameters zipIfSizesAreEqual actualTypeParameters) - ?: error("expect/actual type parameters sizes are checked earlier"), - parentSubstitutor - ) - - if ( - !areCompatibleTypeLists( - expectedValueParameters.toTypeList(substitutor), - actualValueParameters.toTypeList(createEmptySubstitutor()), - insideAnnotationClass - ) || !areCompatibleExpectActualTypes( - expectedReceiverType?.let { substitutor.safeSubstitute(it) }, - actualReceiverType, - parameterOfAnnotationComparisonMode = false - ) - ) { - return ExpectActualMatchingCompatibility.ParameterTypes - } - - if (!areCompatibleTypeParameterUpperBounds(expectedTypeParameters, actualTypeParameters, substitutor)) { - return ExpectActualMatchingCompatibility.FunctionTypeParameterUpperBounds - } - - return null - } - context(ExpectActualMatchingContext<*>) private fun getCallablesCheckingIncompatibility( expectDeclaration: CallableSymbolMarker, @@ -521,22 +453,6 @@ object AbstractExpectActualChecker { return null } - context(ExpectActualMatchingContext<*>) - private fun valueParametersCountCompatible( - expectDeclaration: CallableSymbolMarker, - actualDeclaration: CallableSymbolMarker, - expectValueParameters: List, - actualValueParameters: List, - ): Boolean { - if (expectValueParameters.size == actualValueParameters.size) return true - - return if (expectDeclaration.isAnnotationConstructor() && actualDeclaration.isAnnotationConstructor()) { - expectValueParameters.isEmpty() && actualValueParameters.all { it.hasDefaultValue } - } else { - false - } - } - context(ExpectActualMatchingContext<*>) private fun areCompatibleTypeLists( expectedTypes: List, @@ -720,11 +636,6 @@ object AbstractExpectActualChecker { // ---------------------------------------- Utils ---------------------------------------- - context(ExpectActualMatchingContext<*>) - private fun List.toTypeList(substitutor: TypeSubstitutorMarker): List { - return this.map { substitutor.safeSubstitute(it.returnType) } - } - private inline fun equalsBy(first: List, second: List, selector: (T) -> K): Boolean { for (i in first.indices) { if (selector(first[i]) != selector(second[i])) return false diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/ExpectActualMatchingContext.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/ExpectActualMatchingContext.kt index 4253a522510..dca5f5d5f73 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/ExpectActualMatchingContext.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/ExpectActualMatchingContext.kt @@ -224,7 +224,6 @@ interface ExpectActualMatchingContext : TypeSystemC expectClass: RegularClassSymbolMarker, actualClass: RegularClassSymbolMarker, actualMember: DeclarationSymbolMarker, - checkClassScopesCompatibility: Boolean, ): Map fun DeclarationSymbolMarker.getSourceElement(): SourceElementMarker