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 4a350e6f199..5ed9f4f9b09 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 @@ -44772,6 +44772,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia public void testConstructorCaseSpace() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + + @Test + @TestMetadata("typeCase.kt") + public void testTypeCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt"); + } } } 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 c7e4c8283ff..c67ae9327bb 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 @@ -44772,6 +44772,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated public void testConstructorCaseSpace() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + + @Test + @TestMetadata("typeCase.kt") + public void testTypeCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt"); + } } } 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 f4ebe4f624d..ab123aaad89 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 @@ -42650,6 +42650,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir public void testConstructorCaseSpace() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + + @Test + @TestMetadata("typeCase.kt") + public void testTypeCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt"); + } } } 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 e53c10aaf35..2d1d092d4e2 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 @@ -42770,6 +42770,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia public void testConstructorCaseSpace() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + + @Test + @TestMetadata("typeCase.kt") + public void testTypeCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt"); + } } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.fir.kt new file mode 100644 index 00000000000..729ee4c8cf6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.fir.kt @@ -0,0 +1,28 @@ +// ISSUE: KT-56520 (cases 1, 5, 6) +// 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 foo(): Any? = null + +// K1: misses both some.HashMap and java.util.HashMap due to ambiguous classifiers, takes kotlin.collections.HashMap from the next scope +// K2: properly reports ambiguity +@Suppress("UNCHECKED_CAST") +fun test() = foo() as HashMap // Case 1 + +// Similar behavior to test() above +val bar: HashMap? = null // Case 5 + +// Similar behavior to test() above +val baz = foo() is HashMap<*, *> // Case 6 + diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.fir.txt new file mode 100644 index 00000000000..02ab7650088 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.fir.txt @@ -0,0 +1,11 @@ +FILE: test.kt + public final fun foo(): R|kotlin/Any?| { + ^foo Null(null) + } + @R|kotlin/Suppress|(names = vararg(String(UNCHECKED_CAST))) public final fun test(): { + ^test (R|/foo|() as ) + } + public final val bar: = Null(null) + public get(): + public final val baz: R|kotlin/Boolean| = (R|/foo|() is ) + public get(): R|kotlin/Boolean| diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt new file mode 100644 index 00000000000..474ddd9ca3c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt @@ -0,0 +1,27 @@ +// ISSUE: KT-56520 (cases 1, 5, 6) +// 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 foo(): Any? = null + +// K1: misses both some.HashMap and java.util.HashMap due to ambiguous classifiers, takes kotlin.collections.HashMap from the next scope +// K2: properly reports ambiguity +@Suppress("UNCHECKED_CAST") +fun test() = foo() as HashMap // Case 1 + +// Similar behavior to test() above +val bar: HashMap? = null // Case 5 + +// Similar behavior to test() above +val baz = foo() is HashMap<*, *> // Case 6 diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.txt b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.txt new file mode 100644 index 00000000000..5f91791aa45 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.txt @@ -0,0 +1,82 @@ +package + +public val bar: kotlin.collections.HashMap? /* = java.util.HashMap? */ = null +public val baz: kotlin.Boolean +public fun foo(): kotlin.Any? +@kotlin.Suppress(names = {"UNCHECKED_CAST"}) 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 a425b42eecd..3d6daafa600 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 @@ -44830,6 +44830,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testConstructorCaseSpace() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/constructorCaseSpace.kt"); } + + @Test + @TestMetadata("typeCase.kt") + public void testTypeCase() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/ambiguousTypeReferences/typeCase.kt"); + } } }