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 ffcd7307a15..3d980b9fc39 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 @@ -22,8 +22,10 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.types.classId import org.jetbrains.kotlin.mpp.DeclarationSymbolMarker +import org.jetbrains.kotlin.resolve.calls.mpp.AbstractExpectActualMatcher import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualMatchingCompatibility +// TODO KT-62913 create one more ExpectActualCheckingCompatibility incompatibility, and replace this checker with this incompatibility internal object FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker : FirRegularClassChecker() { override fun check(declaration: FirRegularClass, context: CheckerContext, reporter: DiagnosticReporter) { if (!context.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects) || @@ -38,6 +40,12 @@ internal object FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker : Fir val expectedSingleCandidate = actualClassSymbol.getSingleExpectForActualOrNull() ?: return val expectClassSymbol = expectedSingleCandidate as FirRegularClassSymbol + val expectActualMatchingContext = context.session.expectActualMatchingContextFactory.create( + context.session, context.scopeSession, + allowedWritingMemberExpectForActualMapping = true, + ) + AbstractExpectActualMatcher.recursivelyMatchClassScopes(expectClassSymbol, actualClassSymbol, expectActualMatchingContext) + val matchingContext = context.session.expectActualMatchingContextFactory.create(context.session, context.scopeSession) val problematicExpectMembers = with(matchingContext) { findProblematicExpectMembers(expectClassSymbol, actualClassSymbol) } if (problematicExpectMembers.isNotEmpty()) { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/ExpectActualAttributes.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/ExpectActualAttributes.kt index b64affc6b40..9c4246fe527 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/ExpectActualAttributes.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/ExpectActualAttributes.kt @@ -94,4 +94,5 @@ typealias MemberExpectForActualData = * * See `/docs/fir/k2_kmp.md` */ +// TODO this cache is questionable. Maybe we want to drop it KT-62913 var FirRegularClass.memberExpectForActual: MemberExpectForActualData? by FirDeclarationDataRegistry.data(MemberExpectForActualAttributeKey) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualMatcher.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualMatcher.kt index 25d39d4e751..f686365e35d 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualMatcher.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/mpp/AbstractExpectActualMatcher.kt @@ -9,8 +9,6 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.mpp.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames -import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCheckingCompatibility -import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualMatchingCompatibility import org.jetbrains.kotlin.types.model.KotlinTypeMarker import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker @@ -78,12 +76,18 @@ object AbstractExpectActualMatcher { ExpectActualMatchingCompatibility.MatchedSuccessfully } - context(ExpectActualMatchingContext<*>) - private fun matchClassScopes( + fun recursivelyMatchClassScopes( // todo drop KT-62913 expectClassSymbol: RegularClassSymbolMarker, actualClassSymbol: RegularClassSymbolMarker, - substitutor: TypeSubstitutorMarker, - ) { + context: ExpectActualMatchingContext<*>, + ): Unit = with(context) { + val expectTypeParameterSymbols = expectClassSymbol.typeParameters + val actualTypeParameterSymbols = actualClassSymbol.typeParameters + val substitutor = createExpectActualTypeParameterSubstitutor( + (expectTypeParameterSymbols zipIfSizesAreEqual actualTypeParameterSymbols) ?: return, + parentSubstitutor = null, + ) + val actualMembersByName = actualClassSymbol.collectAllMembers(isActualDeclaration = true).groupBy { it.name } outer@ for (expectMember in expectClassSymbol.collectAllMembers(isActualDeclaration = false)) {