~
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 dd5ae82..67bcd1b 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
@@ -13881,6 +13881,12 @@
}
@Test
+ @TestMetadata("starImportAmbiguity.kt")
+ public void testStarImportAmbiguity() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt");
+ }
+
+ @Test
@TestMetadata("StarImportFromObject.kt")
public void testStarImportFromObject() throws Exception {
runTest("compiler/testData/diagnostics/tests/imports/StarImportFromObject.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 1e8a3f8..e2c334d 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
@@ -13881,6 +13881,12 @@
}
@Test
+ @TestMetadata("starImportAmbiguity.kt")
+ public void testStarImportAmbiguity() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt");
+ }
+
+ @Test
@TestMetadata("StarImportFromObject.kt")
public void testStarImportFromObject() throws Exception {
runTest("compiler/testData/diagnostics/tests/imports/StarImportFromObject.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 75fff2a..e61acd1 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
@@ -13881,6 +13881,12 @@
}
@Test
+ @TestMetadata("starImportAmbiguity.kt")
+ public void testStarImportAmbiguity() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt");
+ }
+
+ @Test
@TestMetadata("StarImportFromObject.kt")
public void testStarImportFromObject() throws Exception {
runTest("compiler/testData/diagnostics/tests/imports/StarImportFromObject.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 54de2a4..283c0e6 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
@@ -13887,6 +13887,12 @@
}
@Test
+ @TestMetadata("starImportAmbiguity.kt")
+ public void testStarImportAmbiguity() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt");
+ }
+
+ @Test
@TestMetadata("StarImportFromObject.kt")
public void testStarImportFromObject() throws Exception {
runTest("compiler/testData/diagnostics/tests/imports/StarImportFromObject.kt");
diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt
index 1407716..04c49ca 100644
--- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt
+++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ConstructorProcessing.kt
@@ -42,23 +42,23 @@
includeInnerConstructors: Boolean,
processor: (FirCallableSymbol<*>) -> Unit
) {
- val (matchedClassifierSymbol, substitutor) = getFirstClassifierOrNull(callInfo, session, bodyResolveComponents) ?: return
- val matchedClassSymbol = matchedClassifierSymbol as? FirClassLikeSymbol<*> ?: return
+ for ((matchedClassifierSymbol, substitutor) in getClassifierResults(callInfo, session, bodyResolveComponents)) {
+ val matchedClassSymbol = matchedClassifierSymbol as? FirClassLikeSymbol<*> ?: continue
+ processConstructors(
+ matchedClassSymbol,
+ substitutor,
+ processor,
+ session,
+ bodyResolveComponents,
+ includeInnerConstructors
+ )
- processConstructors(
- matchedClassSymbol,
- substitutor,
- processor,
- session,
- bodyResolveComponents,
- includeInnerConstructors
- )
-
- processSyntheticConstructors(
- matchedClassSymbol,
- processor,
- bodyResolveComponents
- )
+ processSyntheticConstructors(
+ matchedClassSymbol,
+ processor,
+ bodyResolveComponents
+ )
+ }
}
internal fun FirScope.processFunctionsAndConstructorsByName(
@@ -110,46 +110,27 @@
return deprecation != null && deprecation.deprecationLevel == DeprecationLevelValue.HIDDEN
}
-private fun FirScope.getFirstClassifierOrNull(
+private fun FirScope.getClassifierResults(
callInfo: CallInfo,
session: FirSession,
bodyResolveComponents: BodyResolveComponents
-): SymbolWithSubstitutor? {
+): List<SymbolWithSubstitutor> {
var isSuccessResult = false
- var isAmbiguousResult = false
- var result: SymbolWithSubstitutor? = null
+ val result = mutableListOf<SymbolWithSubstitutor>()
processClassifiersByNameWithSubstitution(callInfo.name) { symbol, substitutor ->
val classifierDeclaration = symbol.fir
val isSuccessCandidate = !classifierDeclaration.isInvisibleOrHidden(session, bodyResolveComponents)
- when {
- isSuccessCandidate && !isSuccessResult -> {
- // successful result is better than unsuccessful
- isSuccessResult = true
- isAmbiguousResult = false
- result = SymbolWithSubstitutor(symbol, substitutor)
- }
- result?.symbol === symbol -> {
- // miss identical results
- return@processClassifiersByNameWithSubstitution
- }
- result != null -> {
- if (isSuccessResult == isSuccessCandidate) {
- // results are similar => ambiguity
- isAmbiguousResult = true
- } else {
- // ignore unsuccessful result if we have successful one
- }
- }
- else -> {
- // result == null: any result is better than no result
- isSuccessResult = isSuccessCandidate
- result = SymbolWithSubstitutor(symbol, substitutor)
- }
+ if (!isSuccessResult && isSuccessCandidate) {
+ // successful result is better than unsuccessful
+ isSuccessResult = true
+ result.clear()
}
+
+ result.add(SymbolWithSubstitutor(symbol, substitutor))
}
- return result.takeUnless { isAmbiguousResult }
+ return result
}
private fun processSyntheticConstructors(
diff --git a/compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt b/compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt
index 16ad5c0..062e687 100644
--- a/compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt
+++ b/compiler/testData/diagnostics/tests/imports/NestedClassClash.fir.kt
@@ -18,7 +18,7 @@
import a.D.<!CONFLICTING_IMPORT!>B<!>
fun test(b: <!OVERLOAD_RESOLUTION_AMBIGUITY!>B<!>) {
- <!UNRESOLVED_REFERENCE!>B<!>()
+ <!OVERLOAD_RESOLUTION_AMBIGUITY!>B<!>()
}
// FILE: d.kt
@@ -27,5 +27,5 @@
// todo ambiguvity here
fun test2(b: <!OVERLOAD_RESOLUTION_AMBIGUITY!>B<!>) {
- <!UNRESOLVED_REFERENCE!>B<!>()
+ <!OVERLOAD_RESOLUTION_AMBIGUITY!>B<!>()
}
diff --git a/compiler/testData/diagnostics/tests/imports/starImportAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/imports/starImportAmbiguity.fir.kt
new file mode 100644
index 0000000..fdcbe9a
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/imports/starImportAmbiguity.fir.kt
@@ -0,0 +1,19 @@
+// ISSUE: KT-56520
+// FULL_JDK
+// FILE: some/HashMap.java
+package some;
+
+public class HashMap<K, V> extends java.util.HashMap<K, V> {}
+
+// FILE: test.kt
+import java.util.*
+import some.*
+
+fun foo(): Any? = null
+
+fun test() {
+ // Should be OVERLOAD_RESOLUTION_AMBIGUITY in K2
+ val map = foo() as <!OVERLOAD_RESOLUTION_AMBIGUITY!>HashMap<String, String><!>
+ // Should be OVERLOAD_RESOLUTION_AMBIGUITY in K2
+ val map2 = <!OVERLOAD_RESOLUTION_AMBIGUITY!>HashMap<!><String, String>()
+}
diff --git a/compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt b/compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt
new file mode 100644
index 0000000..74913f3
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt
@@ -0,0 +1,19 @@
+// ISSUE: KT-56520
+// FULL_JDK
+// FILE: some/HashMap.java
+package some;
+
+public class HashMap<K, V> extends java.util.HashMap<K, V> {}
+
+// FILE: test.kt
+import java.util.*
+import some.*
+
+fun foo(): Any? = null
+
+fun test() {
+ // Should be OVERLOAD_RESOLUTION_AMBIGUITY in K2
+ val map = foo() <!UNCHECKED_CAST!>as HashMap<String, String><!>
+ // Should be OVERLOAD_RESOLUTION_AMBIGUITY in K2
+ val map2 = HashMap<String, String>()
+}
diff --git a/compiler/testData/diagnostics/tests/overload/disambiguateByFailedAbstractClassCheck.fir.kt b/compiler/testData/diagnostics/tests/overload/disambiguateByFailedAbstractClassCheck.fir.kt
new file mode 100644
index 0000000..9f23f1e
--- /dev/null
+++ b/compiler/testData/diagnostics/tests/overload/disambiguateByFailedAbstractClassCheck.fir.kt
@@ -0,0 +1,33 @@
+// !WITH_NEW_IFERENCE
+// !DIAGNOSTICS: -UNUSED_PARAMETER
+
+// FILE: packageA.kt
+
+package a
+
+abstract class Cls
+abstract class Cls2
+
+// FILE: packageB.kt
+
+package b
+
+fun Cls() {}
+class Cls2
+
+// FILE: test.kt
+
+package c
+
+import a.*
+import b.*
+
+fun take(arg: Any) {}
+
+fun test() {
+ <!OVERLOAD_RESOLUTION_AMBIGUITY!>Cls<!>()
+ take(<!OVERLOAD_RESOLUTION_AMBIGUITY!>Cls<!>())
+
+ <!OVERLOAD_RESOLUTION_AMBIGUITY!>Cls2<!>()
+ take(<!OVERLOAD_RESOLUTION_AMBIGUITY!>Cls2<!>())
+}
diff --git a/compiler/testData/diagnostics/tests/overload/disambiguateByFailedAbstractClassCheck.kt b/compiler/testData/diagnostics/tests/overload/disambiguateByFailedAbstractClassCheck.kt
index 2557173..8028e8e 100644
--- a/compiler/testData/diagnostics/tests/overload/disambiguateByFailedAbstractClassCheck.kt
+++ b/compiler/testData/diagnostics/tests/overload/disambiguateByFailedAbstractClassCheck.kt
@@ -1,4 +1,3 @@
-// FIR_IDENTICAL
// !WITH_NEW_IFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER
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 5178a47..d4e5c55 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
@@ -13887,6 +13887,12 @@
}
@Test
+ @TestMetadata("starImportAmbiguity.kt")
+ public void testStarImportAmbiguity() throws Exception {
+ runTest("compiler/testData/diagnostics/tests/imports/starImportAmbiguity.kt");
+ }
+
+ @Test
@TestMetadata("StarImportFromObject.kt")
public void testStarImportFromObject() throws Exception {
runTest("compiler/testData/diagnostics/tests/imports/StarImportFromObject.kt");