From 6049f8657b192be9291a6fddb4dec20a2062dfc3 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 26 Oct 2023 11:57:05 +0200 Subject: [PATCH] K2: add test for KT-56520, case (2), constructors In this test, K1 resolves to kotlin.collections.HashMap /* = java.util.HashMap */ K2 does the similar, but fun processConstructors from ConstructorProcessing.kt makes a type alias substitution, so in fact constructor of expanded java.util.HashMap is processed. Pay attention that both frontends ignore some.HashMap and java.util.HashMap due to ambiguous classifiers in explicit star importing scope. See FirScope.processConstructorsByName in ConstructorProcessing.kt --- ...CompilerTestFE10TestdataTestGenerated.java | 16 ++++ ...sticCompilerFE10TestDataTestGenerated.java | 16 ++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 16 ++++ ...siOldFrontendDiagnosticsTestGenerated.java | 16 ++++ .../constructorCase.fir.txt | 4 + .../constructorCase.kt | 21 +++++ .../constructorCase.txt | 79 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 16 ++++ 8 files changed, 184 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.fir.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.txt 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 73e7ff696fe..09f7ea8ab76 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 @@ -44751,6 +44751,22 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia public void testSameNameClassesFromSupertypes() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/sameNameClassesFromSupertypes.kt"); } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences") + @TestDataPath("$PROJECT_ROOT") + public class AmbiguousTypeReferences { + @Test + public void testAllFilesPresentInAmbiguousTypeReferences() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("constructorCase.kt") + public void testConstructorCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt"); + } + } } @Nested 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 2c487edb790..6e3f67d8ff2 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 @@ -44751,6 +44751,22 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated public void testSameNameClassesFromSupertypes() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/sameNameClassesFromSupertypes.kt"); } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences") + @TestDataPath("$PROJECT_ROOT") + public class AmbiguousTypeReferences { + @Test + public void testAllFilesPresentInAmbiguousTypeReferences() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("constructorCase.kt") + public void testConstructorCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt"); + } + } } @Nested 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 da18c5148cc..69f5241336d 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 @@ -42629,6 +42629,22 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir public void testSameNameClassesFromSupertypes() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/sameNameClassesFromSupertypes.kt"); } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences") + @TestDataPath("$PROJECT_ROOT") + public class AmbiguousTypeReferences { + @Test + public void testAllFilesPresentInAmbiguousTypeReferences() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("constructorCase.kt") + public void testConstructorCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt"); + } + } } @Nested 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 f8fc8fd2522..ae06d8f38b4 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 @@ -42749,6 +42749,22 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia public void testSameNameClassesFromSupertypes() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/sameNameClassesFromSupertypes.kt"); } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences") + @TestDataPath("$PROJECT_ROOT") + public class AmbiguousTypeReferences { + @Test + public void testAllFilesPresentInAmbiguousTypeReferences() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("constructorCase.kt") + public void testConstructorCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt"); + } + } } @Nested diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.fir.txt new file mode 100644 index 00000000000..32dbd2e7630 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.fir.txt @@ -0,0 +1,4 @@ +FILE: test.kt + public final fun test(): R|java/util/HashMap| { + ^test R|java/util/HashMap.HashMap|() + } diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt new file mode 100644 index 00000000000..067ae3843f5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt @@ -0,0 +1,21 @@ +// FIR_IDENTICAL +// ISSUE: KT-56520 (case 2) +// FIR_DUMP +// FULL_JDK + +// FILE: some/HashMap.java + +package some; + +public class HashMap extends java.util.HashMap {} + +// FILE: test.kt + +import java.util.* +import some.* + +fun test() = + // Ok in both K1 & K2. + // K1 resolves this to kotlin.collections.HashMap. + // K2 resolves this to java.util.HashMap + HashMap() diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.txt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.txt new file mode 100644 index 00000000000..33eed1bf770 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.txt @@ -0,0 +1,79 @@ +package + +public fun test(): kotlin.collections.HashMap /* = java.util.HashMap */ + +package some { + + public open class HashMap : java.util.HashMap { + public constructor HashMap() + public open override /*1*/ /*fake_override*/ val entries: kotlin.collections.MutableSet> + invisible_fake final override /*1*/ /*fake_override*/ var entrySet: kotlin.collections.(Mutable)Set!>! + invisible_fake final override /*1*/ /*fake_override*/ var keySet: kotlin.collections.(Mutable)Set! + public open override /*1*/ /*fake_override*/ val keys: kotlin.collections.MutableSet + invisible_fake final override /*1*/ /*fake_override*/ val loadFactor: kotlin.Float + invisible_fake final override /*1*/ /*fake_override*/ var modCount: kotlin.Int + invisible_fake final override /*1*/ /*fake_override*/ var size: kotlin.Int + public open override /*1*/ /*fake_override*/ val size: kotlin.Int + invisible_fake final override /*1*/ /*fake_override*/ var table: kotlin.Array<(out) java.util.HashMap.Node!>! + invisible_fake final override /*1*/ /*fake_override*/ var threshold: kotlin.Int + invisible_fake final override /*1*/ /*fake_override*/ var values: kotlin.collections.(Mutable)Collection! + public open override /*1*/ /*fake_override*/ val values: kotlin.collections.MutableCollection + invisible_fake open override /*1*/ /*fake_override*/ fun afterNodeAccess(/*0*/ p0: java.util.HashMap.Node!): kotlin.Unit + invisible_fake open override /*1*/ /*fake_override*/ fun afterNodeInsertion(/*0*/ p0: kotlin.Boolean): kotlin.Unit + invisible_fake open override /*1*/ /*fake_override*/ fun afterNodeRemoval(/*0*/ p0: java.util.HashMap.Node!): kotlin.Unit + invisible_fake final override /*1*/ /*fake_override*/ fun capacity(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun clear(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public open override /*1*/ /*fake_override*/ fun compute(/*0*/ p0: K!, /*1*/ p1: java.util.function.BiFunction): V? + public open override /*1*/ /*fake_override*/ fun computeIfAbsent(/*0*/ p0: K!, /*1*/ p1: java.util.function.Function): V! + public open override /*1*/ /*fake_override*/ fun computeIfPresent(/*0*/ p0: K!, /*1*/ p1: java.util.function.BiFunction): V? + public open override /*1*/ /*fake_override*/ fun containsKey(/*0*/ key: K!): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun containsValue(/*0*/ value: V!): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun forEach(/*0*/ p0: java.util.function.BiConsumer): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun get(/*0*/ key: K!): V? + invisible_fake final override /*1*/ /*fake_override*/ fun getNode(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Any!): java.util.HashMap.Node! + public open override /*1*/ /*fake_override*/ fun getOrDefault(/*0*/ key: K!, /*1*/ defaultValue: V!): V! + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + invisible_fake open override /*1*/ /*fake_override*/ fun internalWriteEntries(/*0*/ p0: java.io.ObjectOutputStream!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun isEmpty(): kotlin.Boolean + invisible_fake final override /*1*/ /*fake_override*/ fun loadFactor(): kotlin.Float + public open override /*1*/ /*fake_override*/ fun merge(/*0*/ p0: K!, /*1*/ p1: V & Any, /*2*/ p2: java.util.function.BiFunction): V? + invisible_fake open override /*1*/ /*fake_override*/ fun newNode(/*0*/ p0: kotlin.Int, /*1*/ p1: K!, /*2*/ p2: V!, /*3*/ p3: java.util.HashMap.Node!): java.util.HashMap.Node! + invisible_fake open override /*1*/ /*fake_override*/ fun newTreeNode(/*0*/ p0: kotlin.Int, /*1*/ p1: K!, /*2*/ p2: V!, /*3*/ p3: java.util.HashMap.Node!): java.util.HashMap.TreeNode! + public open override /*1*/ /*fake_override*/ fun put(/*0*/ key: K!, /*1*/ value: V!): V? + public open override /*1*/ /*fake_override*/ fun putAll(/*0*/ from: kotlin.collections.Map): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun putIfAbsent(/*0*/ p0: K!, /*1*/ p1: V!): V? + invisible_fake final override /*1*/ /*fake_override*/ fun putMapEntries(/*0*/ p0: (kotlin.collections.MutableMap..kotlin.collections.Map?), /*1*/ p1: kotlin.Boolean): kotlin.Unit + invisible_fake final override /*1*/ /*fake_override*/ fun putVal(/*0*/ p0: kotlin.Int, /*1*/ p1: K!, /*2*/ p2: V!, /*3*/ p3: kotlin.Boolean, /*4*/ p4: kotlin.Boolean): V! + invisible_fake open override /*1*/ /*fake_override*/ fun readObject(/*0*/ p0: java.io.ObjectInputStream!): kotlin.Unit + invisible_fake open override /*1*/ /*fake_override*/ fun reinitialize(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun remove(/*0*/ key: K!): V? + public open override /*1*/ /*fake_override*/ fun remove(/*0*/ key: K!, /*1*/ value: V!): kotlin.Boolean + invisible_fake final override /*1*/ /*fake_override*/ fun removeNode(/*0*/ p0: kotlin.Int, /*1*/ p1: kotlin.Any!, /*2*/ p2: kotlin.Any!, /*3*/ p3: kotlin.Boolean, /*4*/ p4: kotlin.Boolean): java.util.HashMap.Node! + public open override /*1*/ /*fake_override*/ fun replace(/*0*/ p0: K!, /*1*/ p1: V!): V? + public open override /*1*/ /*fake_override*/ fun replace(/*0*/ p0: K!, /*1*/ p1: V!, /*2*/ p2: V!): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun replaceAll(/*0*/ p0: java.util.function.BiFunction): kotlin.Unit + invisible_fake open override /*1*/ /*fake_override*/ fun replacementNode(/*0*/ p0: java.util.HashMap.Node!, /*1*/ p1: java.util.HashMap.Node!): java.util.HashMap.Node! + invisible_fake open override /*1*/ /*fake_override*/ fun replacementTreeNode(/*0*/ p0: java.util.HashMap.Node!, /*1*/ p1: java.util.HashMap.Node!): java.util.HashMap.TreeNode! + invisible_fake final override /*1*/ /*fake_override*/ fun resize(): kotlin.Array<(out) java.util.HashMap.Node!>! + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + invisible_fake final override /*1*/ /*fake_override*/ fun treeifyBin(/*0*/ p0: kotlin.Array<(out) java.util.HashMap.Node!>!, /*1*/ p1: kotlin.Int): kotlin.Unit + invisible_fake open override /*1*/ /*fake_override*/ fun writeObject(/*0*/ p0: java.io.ObjectOutputStream!): kotlin.Unit + + // Static members + invisible_fake const final override /*1*/ /*fake_override*/ val DEFAULT_INITIAL_CAPACITY: kotlin.Int = 16 + invisible_fake const final override /*1*/ /*fake_override*/ val DEFAULT_LOAD_FACTOR: kotlin.Float = 0.75.toFloat() + invisible_fake const final override /*1*/ /*fake_override*/ val MAXIMUM_CAPACITY: kotlin.Int = 1073741824 + invisible_fake const final override /*1*/ /*fake_override*/ val MIN_TREEIFY_CAPACITY: kotlin.Int = 64 + invisible_fake const final override /*1*/ /*fake_override*/ val TREEIFY_THRESHOLD: kotlin.Int = 8 + invisible_fake const final override /*1*/ /*fake_override*/ val UNTREEIFY_THRESHOLD: kotlin.Int = 6 + invisible_fake const final override /*1*/ /*fake_override*/ val serialVersionUID: kotlin.Long = 362498820763181265.toLong() + invisible_fake open override /*1*/ /*fake_override*/ fun comparableClassFor(/*0*/ p0: kotlin.Any!): java.lang.Class<*>! + invisible_fake open override /*1*/ /*fake_override*/ fun compareComparables(/*0*/ p0: java.lang.Class<*>!, /*1*/ p1: kotlin.Any!, /*2*/ p2: kotlin.Any!): kotlin.Int + invisible_fake open override /*1*/ /*fake_override*/ fun eq(/*0*/ p0: kotlin.Any!, /*1*/ p1: kotlin.Any!): kotlin.Boolean + invisible_fake final override /*1*/ /*fake_override*/ fun hash(/*0*/ p0: kotlin.Any!): kotlin.Int + invisible_fake final override /*1*/ /*fake_override*/ fun tableSizeFor(/*0*/ p0: kotlin.Int): kotlin.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 421e5e29f0b..edcda2a2bb3 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 @@ -44809,6 +44809,22 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testSameNameClassesFromSupertypes() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/sameNameClassesFromSupertypes.kt"); } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences") + @TestDataPath("$PROJECT_ROOT") + public class AmbiguousTypeReferences { + @Test + public void testAllFilesPresentInAmbiguousTypeReferences() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("constructorCase.kt") + public void testConstructorCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCase.kt"); + } + } } @Nested