From a9ceae9667656459a4e5c7a941cefabfc0bf8f0d Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 4 Oct 2023 16:10:50 +0300 Subject: [PATCH] [FIR] Add the privateInFileInDifferentModule test We only see the redeclaration diagnostics on the declarations inside the second file, because of `FirRecorder::visitRegularClass`. `data.state.classifierContainerFileMap` references the last file, so when checking the visibility of the first `private class C { ... }` (when collecting declarations that conflict with the second `private class C`) the provider returns the second file instead of the first one, so the class behaves as it is visible, and `collectTopLevelConflict` returns in this case. As for why `INVISIBLE_*`s are reported inside the first file: this is because `data.state.classifierMap` stores the last classifier it sees instead of the first one. ^KT-62537 --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 +++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 +++++ .../privateInFileInDifferentModule.fir.kt | 25 +++++++++++++++++++ .../privateInFileInDifferentModule.kt | 25 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 7 files changed, 80 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.fir.kt create mode 100644 compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.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 71ba64de1c0..1743701e718 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 @@ -35214,6 +35214,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/typealias/privateInFile.kt"); } + @Test + @TestMetadata("privateInFileInDifferentModule.kt") + public void testPrivateInFileInDifferentModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt"); + } + @Test @TestMetadata("projectionsInTypeAliasConstructor.kt") public void testProjectionsInTypeAliasConstructor() 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 d77c701c476..eba212a0e02 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 @@ -35214,6 +35214,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/typealias/privateInFile.kt"); } + @Test + @TestMetadata("privateInFileInDifferentModule.kt") + public void testPrivateInFileInDifferentModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt"); + } + @Test @TestMetadata("projectionsInTypeAliasConstructor.kt") public void testProjectionsInTypeAliasConstructor() 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 751e97ba6ac..182b6517d66 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 @@ -35214,6 +35214,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/typealias/privateInFile.kt"); } + @Test + @TestMetadata("privateInFileInDifferentModule.kt") + public void testPrivateInFileInDifferentModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt"); + } + @Test @TestMetadata("projectionsInTypeAliasConstructor.kt") public void testProjectionsInTypeAliasConstructor() 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 c8ac3aec526..3ddea72ab88 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 @@ -35328,6 +35328,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/typealias/privateInFile.kt"); } + @Test + @TestMetadata("privateInFileInDifferentModule.kt") + public void testPrivateInFileInDifferentModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt"); + } + @Test @TestMetadata("projectionsInTypeAliasConstructor.kt") public void testProjectionsInTypeAliasConstructor() throws Exception { diff --git a/compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.fir.kt b/compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.fir.kt new file mode 100644 index 00000000000..27cad13717f --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.fir.kt @@ -0,0 +1,25 @@ +// ISSUE: KT-62537 +// MODULE: m1 +// FILE: file1.kt +private class C { + companion object +} + +private typealias TA = C + +private val test1: C = C() +private val test1co: C.Companion = C + +private val test2: TA = TA() +private val test2co = TA + +// MODULE: m2(m1) +// FILE: file2.kt +private val test1: C = C() +private val test1co: C.Companion = C + +private val test2: TA = TA() +private val test2co = TA + +private class C +private typealias TA = Int diff --git a/compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt b/compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt new file mode 100644 index 00000000000..f92cd219385 --- /dev/null +++ b/compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt @@ -0,0 +1,25 @@ +// ISSUE: KT-62537 +// MODULE: m1 +// FILE: file1.kt +private class C { + companion object +} + +private typealias TA = C + +private val test1: C = C() +private val test1co: C.Companion = C + +private val test2: TA = TA() +private val test2co = TA + +// MODULE: m2(m1) +// FILE: file2.kt +private val test1: C = C() +private val test1co: C.Companion = C + +private val test2: TA = TA() +private val test2co = TA + +private class C +private typealias TA = Int 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 29a744998a1..c7108e444d0 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 @@ -37202,6 +37202,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/typealias/privateInFile.kt"); } + @Test + @TestMetadata("privateInFileInDifferentModule.kt") + public void testPrivateInFileInDifferentModule() throws Exception { + runTest("compiler/testData/diagnostics/tests/typealias/privateInFileInDifferentModule.kt"); + } + @Test @TestMetadata("projectionsInTypeAliasConstructor.kt") public void testProjectionsInTypeAliasConstructor() throws Exception {