From b6cae1adccb5c8fc0238b13c86703b93a0d05323 Mon Sep 17 00:00:00 2001 From: Roman Efremov Date: Thu, 22 Jun 2023 16:37:20 +0200 Subject: [PATCH] [FE] Allow @OptionalExpectation to be present only on expect ^KT-58551 --- ...tendMPPDiagnosticsWithLightTreeTestGenerated.java | 6 ++++++ ...ldFrontendMPPDiagnosticsWithPsiTestGenerated.java | 6 ++++++ .../AbstractExpectActualAnnotationMatchChecker.kt | 4 ++++ .../annotationMatching/optionalExpectation.kt | 12 ++++++++++++ .../kotlin/test/runners/DiagnosticTestGenerated.java | 6 ++++++ 5 files changed, 34 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/multiplatform/annotationMatching/optionalExpectation.kt diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java index 503d5af805a..eec286d934a 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated.java @@ -274,6 +274,12 @@ public class FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated extends Abst runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/kotlinAnaloguesForJavaAnnotations.kt"); } + @Test + @TestMetadata("optionalExpectation.kt") + public void testOptionalExpectation() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/optionalExpectation.kt"); + } + @Test @TestMetadata("typealias.kt") public void testTypealias() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java index 0accbe88a08..f7eb49be59a 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendMPPDiagnosticsWithPsiTestGenerated.java @@ -274,6 +274,12 @@ public class FirOldFrontendMPPDiagnosticsWithPsiTestGenerated extends AbstractFi runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/kotlinAnaloguesForJavaAnnotations.kt"); } + @Test + @TestMetadata("optionalExpectation.kt") + public void testOptionalExpectation() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/optionalExpectation.kt"); + } + @Test @TestMetadata("typealias.kt") public void testTypealias() throws Exception { 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 0940c377a0e..5ab2f03648e 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 @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.mpp import org.jetbrains.kotlin.mpp.DeclarationSymbolMarker import org.jetbrains.kotlin.mpp.TypeAliasSymbolMarker +import org.jetbrains.kotlin.name.StandardClassIds object AbstractExpectActualAnnotationMatchChecker { class Incompatibility(val expectSymbol: DeclarationSymbolMarker, val actualSymbol: DeclarationSymbolMarker) @@ -30,6 +31,9 @@ object AbstractExpectActualAnnotationMatchChecker { val actualAnnotationsByName = actualSymbol.annotations.groupBy { it.classId } for (expectAnnotation in expectSymbol.annotations) { + if (expectAnnotation.classId == StandardClassIds.Annotations.OptionalExpectation) { + continue + } val actualAnnotationsWithSameClassId = actualAnnotationsByName[expectAnnotation.classId] ?: emptyList() if (actualAnnotationsWithSameClassId.none { areAnnotationArgumentsEqual(expectAnnotation, it) }) { return Incompatibility(expectSymbol, actualSymbol) diff --git a/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/optionalExpectation.kt b/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/optionalExpectation.kt new file mode 100644 index 00000000000..2e53bf3d47d --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/annotationMatching/optionalExpectation.kt @@ -0,0 +1,12 @@ +// FIR_IDENTICAL +// WITH_STDLIB +// MODULE: m1-common +// FILE: common.kt +@OptIn(ExperimentalMultiplatform::class) +@OptionalExpectation +expect annotation class MyAnnotation + +// MODULE: m1-jvm()()(m1-common) +// FILE: jvm.kt +@OptIn(ExperimentalMultiplatform::class) +actual annotation class MyAnnotation diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 618beb5f082..de59b11fb95 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -22819,6 +22819,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/kotlinAnaloguesForJavaAnnotations.kt"); } + @Test + @TestMetadata("optionalExpectation.kt") + public void testOptionalExpectation() throws Exception { + runTest("compiler/testData/diagnostics/tests/multiplatform/annotationMatching/optionalExpectation.kt"); + } + @Test @TestMetadata("typealias.kt") public void testTypealias() throws Exception {