diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index becc8bc6904..d4ff010c4c2 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -10760,6 +10760,16 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3174.kt"); } + @TestMetadata("kt32862_both.kt") + public void testKt32862_both() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt32862_both.kt"); + } + + @TestMetadata("kt32862_none.kt") + public void testKt32862_none() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt32862_none.kt"); + } + @TestMetadata("kt3301.kt") public void testKt3301() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3301.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index a2178ab0fed..87a95a82a6b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -730,6 +730,7 @@ public interface Errors { DiagnosticFactory1>> NONE_APPLICABLE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1>> CANNOT_COMPLETE_RESOLVE = DiagnosticFactory1.create(ERROR); DiagnosticFactory1>> UNRESOLVED_REFERENCE_WRONG_RECEIVER = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1> CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR); DiagnosticFactory1 REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 5f11d00f6e9..72b77756837 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -828,6 +828,7 @@ public class DefaultErrorMessages { MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS); MAP.put(CANNOT_COMPLETE_RESOLVE, "Cannot choose among the following candidates without completing type inference: {0}", AMBIGUOUS_CALLS); MAP.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: {0}", AMBIGUOUS_CALLS); + MAP.put(CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY, "Callable reference resolution ambiguity: {0}", AMBIGUOUS_CALLABLE_REFERENCES); MAP.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter ''{0}''", NAME); MAP.put(MISSING_RECEIVER, "A receiver of type {0} is required", RENDER_TYPE); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt index 9cbf3451bd5..4e05d947d0b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt @@ -190,10 +190,21 @@ object Renderers { @JvmField val AMBIGUOUS_CALLS = Renderer { calls: Collection> -> val descriptors = calls.map { it.resultingDescriptor } + renderAmbiguousDescriptors(descriptors) + } + + @JvmField + val AMBIGUOUS_CALLABLE_REFERENCES = Renderer { references: Collection -> + renderAmbiguousDescriptors(references) + } + + private fun renderAmbiguousDescriptors(descriptors: Collection): String { val context = RenderingContext.Impl(descriptors) - descriptors + return descriptors .sortedWith(MemberComparator.INSTANCE) - .joinToString(separator = "\n", prefix = "\n") { FQ_NAMES_IN_TYPES.render(it, context) } + .joinToString(separator = "\n", prefix = "\n") { + FQ_NAMES_IN_TYPES.render(it, context) + } } @JvmStatic diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index 20510b7cdfb..5cd63027552 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -32,7 +32,6 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.typeUtil.unCapture import org.jetbrains.kotlin.utils.addToStdlib.safeAs class DiagnosticReporterByTrackingStrategy( @@ -140,6 +139,15 @@ class DiagnosticReporterByTrackingStrategy( } } + CallableReferenceCandidatesAmbiguity::class.java -> { + val ambiguityDiagnostic = diagnostic as CallableReferenceCandidatesAmbiguity + val expression = ambiguityDiagnostic.argument.psiExpression.safeAs() + val candidates = ambiguityDiagnostic.candidates.map { it.candidate } + reportIfNonNull(expression) { + trace.report(CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY.on(it.callableReference, candidates)) + } + } + ArgumentTypeMismatchDiagnostic::class.java -> { require(diagnostic is ArgumentTypeMismatchDiagnostic) reportIfNonNull(callArgument.safeAs()?.valueArgument?.getArgumentExpression()) { diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.kt index dc76a67d9fe..00a756e5dc9 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/ambiguityWhenNoApplicableCallableReferenceCandidate.kt @@ -7,5 +7,5 @@ fun foo(y: String) {} fun bar(f: (T) -> Unit) {} fun test() { - bar(::foo) + bar(::foo) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.kt index f87cc868867..67c6b461074 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.kt @@ -31,7 +31,7 @@ fun test() { val t3 = bar(::baz) t3 - bar(::foo) + bar(::foo) } } } diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.kt index 8c4b8a3c168..68d8a34d62b 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/eagerAndPostponedCallableReferences.kt @@ -31,5 +31,5 @@ fun test() { val a6 = foo(::singleA, ::singleB) a6 - foo(::multiple, ::multiple) + foo(::multiple, ::multiple) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.kt index 179dee8495c..29f1c0b7e6b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.kt @@ -6,8 +6,8 @@ class Impl : Inv class Scope(private val implClass: j.Class) { fun foo(c: Collection) { val hm = c.asSequence() - .filter(implClass::isInstance) - .map(implClass::cast) + .filter(implClass::isInstance) + .map(implClass::cast) .toSet() } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index a7a1fbfb03d..7ee2a3f73b1 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10767,6 +10767,16 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3174.kt"); } + @TestMetadata("kt32862_both.kt") + public void testKt32862_both() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt32862_both.kt"); + } + + @TestMetadata("kt32862_none.kt") + public void testKt32862_none() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt32862_none.kt"); + } + @TestMetadata("kt3301.kt") public void testKt3301() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3301.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index b01e901d750..1e20faf371e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -10762,6 +10762,16 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3174.kt"); } + @TestMetadata("kt32862_both.kt") + public void testKt32862_both() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt32862_both.kt"); + } + + @TestMetadata("kt32862_none.kt") + public void testKt32862_none() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt32862_none.kt"); + } + @TestMetadata("kt3301.kt") public void testKt3301() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3301.kt");