From 168717b81136f37fb1cd1308d085beb4d2293b2f Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 27 Oct 2023 15:34:22 +0200 Subject: [PATCH] K2: add test for KT-56520, case (7), qualifier receivers (1) Again, both frontends here ignored classifiers from explicit star imported scope (some.HashMap, java.util.HashMap) because of their ambiguity. In case of K2, it works so due to logic in BodyResolveComponents.resolveRootPartOfQualifier. This function is called to resolve qualifier without receiver --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++ ...sticCompilerFE10TestDataTestGenerated.java | 6 +++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 +++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 +++ .../qualifierForStaticCase.fir.txt | 45 ++++++++++++++++ .../qualifierForStaticCase.kt | 52 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++ 7 files changed, 127 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.fir.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.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 0f83cecfba3..338a91376fc 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 @@ -44779,6 +44779,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + @Test + @TestMetadata("qualifierForStaticCase.kt") + public void testQualifierForStaticCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt"); + } + @Test @TestMetadata("typeCase.kt") public void testTypeCase() 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 576c909ed92..e63bea7e6b0 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 @@ -44779,6 +44779,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + @Test + @TestMetadata("qualifierForStaticCase.kt") + public void testQualifierForStaticCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt"); + } + @Test @TestMetadata("typeCase.kt") public void testTypeCase() 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 5538f121cd1..a76158b3cd0 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 @@ -42657,6 +42657,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + @Test + @TestMetadata("qualifierForStaticCase.kt") + public void testQualifierForStaticCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt"); + } + @Test @TestMetadata("typeCase.kt") public void testTypeCase() 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 e93c55181bb..85ad9180b04 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 @@ -42777,6 +42777,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + @Test + @TestMetadata("qualifierForStaticCase.kt") + public void testQualifierForStaticCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt"); + } + @Test @TestMetadata("typeCase.kt") public void testTypeCase() throws Exception { diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.fir.txt new file mode 100644 index 00000000000..118b2f37fbf --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.fir.txt @@ -0,0 +1,45 @@ +FILE: Map.kt + package some + + public final class Map : R|kotlin/Any| { + public constructor(): R|some/Map| { + super() + } + + public final companion object Companion : R|kotlin/Any| { + private constructor(): R|some/Map.Companion| { + super() + } + + public final fun of(): R|kotlin/Int| { + ^of Int(42) + } + + } + + } +FILE: Map.kt + package other + + public final class Map : R|kotlin/Any| { + public constructor(): R|other/Map| { + super() + } + + } +FILE: test.kt + public final fun test(): { + ^test Q|kotlin/collections/Map|.#() + } +FILE: test2.kt + public final fun test2(): { + ^test2 Q|kotlin/collections/Map|.#() + } +FILE: test3.kt + public final fun test3(): R|ft, kotlin/collections/Map?>| { + ^test3 Q|java/util/Map|.R|java/util/Map.of*s|() + } +FILE: test4.kt + public final fun test4(): R|kotlin/Int| { + ^test4 Q|some/Map|.R|some/Map.Companion.of|() + } diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt new file mode 100644 index 00000000000..de476a3931b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt @@ -0,0 +1,52 @@ +// FIR_IDENTICAL +// ISSUE: KT-56520 (case 7) +// FIR_DUMP +// JDK_KIND: FULL_JDK_17 +// DIAGNOSTICS: -PLATFORM_CLASS_MAPPED_TO_KOTLIN + +// FILE: some/Map.kt + +package some + +class Map { + companion object { + fun of() = 42 + } +} + +// FILE: other/Map.kt + +package other + +class Map + +// FILE: test.kt + +import java.util.* +import some.* + +// K1: misses both some.Map and java.util.Map due to ambiguous classifiers, takes kotlin.collections.Map from the next scope +// K2: works the same way currently. See logic in BodyResolveComponents.resolveRootPartOfQualifier +// (looks like kotlin.collections.Map.of is not available) +fun test() = Map.of() + +// FILE: test2.kt + +import java.util.* +import other.* + +// K1: misses both some.Map and java.util.Map due to ambiguous classifiers, takes kotlin.collections.Map from the next scope +// K2: works the same way currently. See logic in BodyResolveComponents.resolveRootPartOfQualifier +fun test2() = Map.of() + +// FILE: test3.kt + +import java.util.Map + +fun test3() = Map.of() + +// FILE: test4.kt + +import some.Map + +fun test4() = Map.of() 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 7894f73afab..e71bb5ca80d 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 @@ -44837,6 +44837,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + @Test + @TestMetadata("qualifierForStaticCase.kt") + public void testQualifierForStaticCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/qualifierForStaticCase.kt"); + } + @Test @TestMetadata("typeCase.kt") public void testTypeCase() throws Exception {