[FIR, IR] Commonize isFakeOverride check for AbstractExpectActualAnnotationMatchChecker

This commit fixes fakeOverrides.fir.kt test that got broken in the
previous commit

Previously isFakeOverride was only checked on IR backend. Now this check
is moved to AbstractExpectActualAnnotationMatchChecker which is used by
both: frontend and backend. That's why frontend no longer reports false
positive ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT

Review: https://jetbrains.team/p/kt/reviews/13094/timeline
This commit is contained in:
Nikita Bobko
2023-11-17 12:35:34 +01:00
committed by teamcity
parent e6bfcc7c65
commit 5b72c127bd
9 changed files with 34 additions and 34 deletions
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.resolve.checkers.OptInNames
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility
import org.jetbrains.kotlin.utils.zipIfSizesAreEqual
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualMatchingCompatibility
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualAnnotationsIncompatibilityType as IncompatibilityType
@@ -53,19 +52,21 @@ object AbstractExpectActualAnnotationMatchChecker {
fun areAnnotationsCompatible(
expectSymbol: DeclarationSymbolMarker,
actualSymbol: DeclarationSymbolMarker,
containingExpectClass: RegularClassSymbolMarker?, // Only necessary for the frontend. IR doesn't use it
context: ExpectActualMatchingContext<*>,
): Incompatibility? = with(context) {
areAnnotationsCompatible(expectSymbol, actualSymbol)
areAnnotationsCompatible(expectSymbol, actualSymbol, containingExpectClass)
}
context (ExpectActualMatchingContext<*>)
private fun areAnnotationsCompatible(
expectSymbol: DeclarationSymbolMarker,
actualSymbol: DeclarationSymbolMarker,
containingExpectClass: RegularClassSymbolMarker?,
): Incompatibility? {
return when (expectSymbol) {
is CallableSymbolMarker -> {
areCallableAnnotationsCompatible(expectSymbol, actualSymbol as CallableSymbolMarker)
areCallableAnnotationsCompatible(expectSymbol, actualSymbol as CallableSymbolMarker, containingExpectClass)
}
is RegularClassSymbolMarker -> {
areClassAnnotationsCompatible(expectSymbol, actualSymbol as ClassLikeSymbolMarker)
@@ -78,7 +79,11 @@ object AbstractExpectActualAnnotationMatchChecker {
private fun areCallableAnnotationsCompatible(
expectSymbol: CallableSymbolMarker,
actualSymbol: CallableSymbolMarker,
containingExpectClass: RegularClassSymbolMarker?,
): Incompatibility? {
// If the expect declaration is fake-override and is incompatible, then it means that it was overridden on actual.
// In such case, regular rules for annotations on overridden declarations apply.
if (expectSymbol.isFakeOverride(containingExpectClass)) return null
commonForClassAndCallableChecks(expectSymbol, actualSymbol)?.let { return it }
areAnnotationsOnValueParametersCompatible(expectSymbol, actualSymbol)?.let { return it }
@@ -316,7 +321,7 @@ object AbstractExpectActualAnnotationMatchChecker {
// Check also incompatible members if only one is found
?: expectToCompatibilityMap.keys.singleOrNull()
?: continue
areAnnotationsCompatible(expectMember, actualMember)?.let { return it }
areAnnotationsCompatible(expectMember, actualMember, expectClass)?.let { return it }
}
return null
}
@@ -156,13 +156,7 @@ interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemC
fun RegularClassSymbolMarker.isNotSamInterface(): Boolean
/*
* Determines should some declaration from expect class scope be checked
* - FE 1.0: skip fake overrides
* - FIR: skip fake overrides
* - IR: skip nothing
*/
fun CallableSymbolMarker.shouldSkipMatching(containingExpectClass: RegularClassSymbolMarker): Boolean
fun CallableSymbolMarker.isFakeOverride(containingExpectClass: RegularClassSymbolMarker?): Boolean
val CallableSymbolMarker.hasStableParameterNames: Boolean