From ab2c129466589714d51e97a03b44e71ee3a74e90 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Fri, 4 Aug 2023 16:01:10 +0200 Subject: [PATCH] [FE, IR] Refactor: extract compatibility check of two annotation lists to separate method This is needed for subsequent checks of annotations set on types, while currently method accepts only declarations. MR: KT-MR-12245 ^KT-60671 --- ...tractExpectActualAnnotationMatchChecker.kt | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) 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 40f5c353fd5..30606674d87 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 @@ -188,12 +188,21 @@ object AbstractExpectActualAnnotationMatchChecker { expectSymbol: DeclarationSymbolMarker, actualSymbol: DeclarationSymbolMarker, ): Incompatibility? { + return areAnnotationListsCompatible(expectSymbol.annotations, actualSymbol.annotations, actualSymbol) + ?.let { Incompatibility(expectSymbol, actualSymbol, actualSymbol.getSourceElement(), it) } + } + + context (ExpectActualMatchingContext<*>) + private fun areAnnotationListsCompatible( + expectAnnotations: List, + actualAnnotations: List, + actualContainerSymbol: DeclarationSymbolMarker, + ): IncompatibilityType? { // TODO(Roman.Efremov, KT-60671): check annotations set on types + val skipSourceAnnotations = actualContainerSymbol.hasSourceAnnotationsErased + val actualAnnotationsByName = actualAnnotations.groupBy { it.classId } - val skipSourceAnnotations = actualSymbol.hasSourceAnnotationsErased - val actualAnnotationsByName = actualSymbol.annotations.groupBy { it.classId } - - for (expectAnnotation in expectSymbol.annotations) { + for (expectAnnotation in expectAnnotations) { val expectClassId = expectAnnotation.classId ?: continue if (expectClassId in SKIPPED_CLASS_IDS || expectAnnotation.isOptIn) { continue @@ -203,24 +212,18 @@ object AbstractExpectActualAnnotationMatchChecker { } val actualAnnotationsWithSameClassId = actualAnnotationsByName[expectClassId] ?: emptyList() if (actualAnnotationsWithSameClassId.isEmpty()) { - return Incompatibility( - expectSymbol, - actualSymbol, - actualSymbol.getSourceElement(), - IncompatibilityType.MissingOnActual(expectAnnotation) - ) + return IncompatibilityType.MissingOnActual(expectAnnotation) } val collectionCompatibilityChecker = getAnnotationCollectionArgumentsCompatibilityChecker(expectClassId) if (actualAnnotationsWithSameClassId.none { areAnnotationArgumentsEqual(expectAnnotation, it, collectionCompatibilityChecker) }) { - val incompatibilityType = if (actualAnnotationsWithSameClassId.size == 1) { + return if (actualAnnotationsWithSameClassId.size == 1) { IncompatibilityType.DifferentOnActual(expectAnnotation, actualAnnotationsWithSameClassId.single()) } else { // In the case of repeatable annotations, we can't choose on which to report IncompatibilityType.MissingOnActual(expectAnnotation) } - return Incompatibility(expectSymbol, actualSymbol, actualSymbol.getSourceElement(), incompatibilityType) } } return null