Report diagnostics about callable reference resolution ambiguity
Found diagnostics were not reported before. #KT-32862 In Progress
This commit is contained in:
@@ -730,6 +730,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> NONE_APPLICABLE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> CANNOT_COMPLETE_RESOLVE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends ResolvedCall<?>>> UNRESOLVED_REFERENCE_WRONG_RECEIVER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, Collection<? extends CallableDescriptor>> CALLABLE_REFERENCE_RESOLUTION_AMBIGUITY = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, TypeParameterDescriptor> TYPE_PARAMETER_AS_REIFIED = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> REIFIED_TYPE_FORBIDDEN_SUBSTITUTION = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
+1
@@ -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);
|
||||
|
||||
@@ -190,10 +190,21 @@ object Renderers {
|
||||
@JvmField
|
||||
val AMBIGUOUS_CALLS = Renderer { calls: Collection<ResolvedCall<*>> ->
|
||||
val descriptors = calls.map { it.resultingDescriptor }
|
||||
renderAmbiguousDescriptors(descriptors)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val AMBIGUOUS_CALLABLE_REFERENCES = Renderer { references: Collection<CallableDescriptor> ->
|
||||
renderAmbiguousDescriptors(references)
|
||||
}
|
||||
|
||||
private fun renderAmbiguousDescriptors(descriptors: Collection<CallableDescriptor>): 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
|
||||
|
||||
+9
-1
@@ -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<KtCallableReferenceExpression>()
|
||||
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<PSIKotlinCallArgument>()?.valueArgument?.getArgumentExpression()) {
|
||||
|
||||
Reference in New Issue
Block a user