From 7429dd4b9468cebf9ef59a4d26ca7981eb00c50e Mon Sep 17 00:00:00 2001 From: "Anastasia.Nekrasova" Date: Mon, 15 Jan 2024 21:23:47 +0200 Subject: [PATCH] K2: Support for inter-module interaction for @SubclassOptInRequired The inter-module interaction was partially supported, but the DiagnosticCompilerTestFE10TestdataTestGenerated and LFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated were failing. This is because the arguments of annotations were not fully resolved in loadExperimentalitiesFromAnnotationTo function. ^KT-60262 Fixed --- ...sticCompilerTestFE10TestdataTestGenerated.java | 6 ++++++ ...agnosticCompilerFE10TestDataTestGenerated.java | 6 ++++++ ...htTreeOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ ...FirPsiOldFrontendDiagnosticsTestGenerated.java | 6 ++++++ .../expression/FirOptInUsageBaseChecker.kt | 1 + .../subclassOptInRequired/Module.fir.kt | 15 +++++++++++++++ .../annotations/subclassOptInRequired/Module.kt | 15 +++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++++ 8 files changed, 61 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 6d690372cc5..9d78b60fb97 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -42301,6 +42301,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt"); } + @Test + @TestMetadata("Module.kt") + public void testModule() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt"); + } + @Test @TestMetadata("NestedClasses.kt") public void testNestedClasses() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index d664ec1bb9f..89d6e92476a 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -42301,6 +42301,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt"); } + @Test + @TestMetadata("Module.kt") + public void testModule() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt"); + } + @Test @TestMetadata("NestedClasses.kt") public void testNestedClasses() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 836c524d117..73ab5b46e9e 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -40015,6 +40015,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt"); } + @Test + @TestMetadata("Module.kt") + public void testModule() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt"); + } + @Test @TestMetadata("NestedClasses.kt") public void testNestedClasses() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 1c5ff4b1125..63e00aa3cc0 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -40135,6 +40135,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt"); } + @Test + @TestMetadata("Module.kt") + public void testModule() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt"); + } + @Test @TestMetadata("NestedClasses.kt") public void testNestedClasses() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt index 0348f93753a..a3fcd6fdc9c 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt @@ -175,6 +175,7 @@ object FirOptInUsageBaseChecker { is FirAnonymousInitializer, is FirDanglingModifierList, is FirFile, is FirTypeParameter, is FirScript, is FirCodeFragment -> {} } + lazyResolveToPhase(FirResolvePhase.ANNOTATION_ARGUMENTS) fir.loadExperimentalitiesFromAnnotationTo(session, result, fromSupertype) if (fir.getAnnotationByClassId(OptInNames.WAS_EXPERIMENTAL_CLASS_ID, session) != null) { diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.fir.kt new file mode 100644 index 00000000000..918a21fc989 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.fir.kt @@ -0,0 +1,15 @@ +// MODULE: a +@file:OptIn(ExperimentalSubclassOptIn::class) +package a + +@RequiresOptIn +annotation class Boom + +@SubclassOptInRequired(Boom::class) +open class B {} + +// MODULE: b(a) +package b +import a.B + +class C : B() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt new file mode 100644 index 00000000000..b472586cd08 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt @@ -0,0 +1,15 @@ +// MODULE: a +@file:OptIn(ExperimentalSubclassOptIn::class) +package a + +@RequiresOptIn +annotation class Boom + +@SubclassOptInRequired(Boom::class) +open class B {} + +// MODULE: b(a) +package b +import a.B + +class C : B() \ No newline at end of file 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 b75b07d9c6b..c74d2260cb0 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 @@ -42301,6 +42301,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/JavaKotlinInterop.kt"); } + @Test + @TestMetadata("Module.kt") + public void testModule() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/Module.kt"); + } + @Test @TestMetadata("NestedClasses.kt") public void testNestedClasses() throws Exception {