@@ -4687,10 +4687,25 @@ static bool diagnoseAmbiguity(
4687
4687
fixes.push_back (entry.second );
4688
4688
}
4689
4689
4690
+ auto emitGeneralFoundCandidateNote = [&]() {
4691
+ // Emit a general "found candidate" note
4692
+ if (decl->getLoc ().isInvalid ()) {
4693
+ if (candidateTypes.insert (type->getCanonicalType ()).second )
4694
+ DE.diagnose (getLoc (commonAnchor), diag::found_candidate_type, type);
4695
+ } else {
4696
+ DE.diagnose (noteLoc, diag::found_candidate);
4697
+ }
4698
+ };
4699
+
4690
4700
if (fixes.size () == 1 ) {
4691
4701
diagnosed &= fixes.front ()->diagnose (solution, /* asNote*/ true );
4692
4702
} else if (!fixes.empty () &&
4693
4703
llvm::all_of (fixes, [&](const ConstraintFix *fix) {
4704
+ // Ignore coercion fixes in this context, to
4705
+ // focus on the argument mismatches.
4706
+ if (fix->getLocator ()->isForCoercion ())
4707
+ return true ;
4708
+
4694
4709
return fix->getLocator ()
4695
4710
->findLast <LocatorPathElt::ApplyArgument>()
4696
4711
.has_value ();
@@ -4704,28 +4719,34 @@ static bool diagnoseAmbiguity(
4704
4719
type->lookThroughAllOptionalTypes ()->getAs <AnyFunctionType>();
4705
4720
assert (fn);
4706
4721
4707
- auto *argList = solution.getArgumentList (fixes.front ()->getLocator ());
4708
- assert (argList);
4709
-
4710
- if (fn->getNumParams () == 1 && argList->isUnary ()) {
4711
- const auto ¶m = fn->getParams ()[0 ];
4712
- auto argTy = solution.getResolvedType (argList->getUnaryExpr ());
4722
+ auto first = llvm::find_if (fixes, [&](const ConstraintFix *fix) {
4723
+ return fix->getLocator ()
4724
+ ->findLast <LocatorPathElt::ApplyArgument>()
4725
+ .has_value ();
4726
+ });
4713
4727
4714
- DE.diagnose (noteLoc, diag::candidate_has_invalid_argument_at_position,
4715
- solution.simplifyType (param.getPlainType ()),
4716
- /* position=*/ 1 , param.isInOut (), argTy);
4728
+ if (first != fixes.end ()) {
4729
+ auto *argList = solution.getArgumentList ((*first)->getLocator ());
4730
+ assert (argList);
4731
+
4732
+ if (fn->getNumParams () == 1 && argList->isUnary ()) {
4733
+ const auto ¶m = fn->getParams ()[0 ];
4734
+ auto argTy = solution.getResolvedType (argList->getUnaryExpr ());
4735
+
4736
+ DE.diagnose (noteLoc,
4737
+ diag::candidate_has_invalid_argument_at_position,
4738
+ solution.simplifyType (param.getPlainType ()),
4739
+ /* position=*/ 1 , param.isInOut (), argTy);
4740
+ } else {
4741
+ DE.diagnose (noteLoc, diag::candidate_partial_match,
4742
+ fn->getParamListAsString (fn->getParams ()));
4743
+ }
4717
4744
} else {
4718
- DE. diagnose (noteLoc, diag::candidate_partial_match,
4719
- fn-> getParamListAsString (fn-> getParams ()) );
4745
+ // Only coercion ambiguity fixes.
4746
+ emitGeneralFoundCandidateNote ( );
4720
4747
}
4721
4748
} else {
4722
- // Emit a general "found candidate" note
4723
- if (decl->getLoc ().isInvalid ()) {
4724
- if (candidateTypes.insert (type->getCanonicalType ()).second )
4725
- DE.diagnose (getLoc (commonAnchor), diag::found_candidate_type, type);
4726
- } else {
4727
- DE.diagnose (noteLoc, diag::found_candidate);
4728
- }
4749
+ emitGeneralFoundCandidateNote ();
4729
4750
}
4730
4751
}
4731
4752
0 commit comments