@@ -422,6 +422,14 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
422
422
return getConstraintLocator (anchor, newPath);
423
423
}
424
424
425
+ ConstraintLocator *
426
+ ConstraintSystem::getConstraintLocatorForAmbiguity (ConstraintLocator *locator) {
427
+ if (locator->findLast <LocatorPathElt::CoercionOperand>()) {
428
+ return getConstraintLocator (simplifyLocatorToAnchor (locator));
429
+ }
430
+ return locator;
431
+ }
432
+
425
433
ConstraintLocator *ConstraintSystem::getImplicitValueConversionLocator (
426
434
ConstraintLocatorBuilder root, ConversionRestrictionKind restriction) {
427
435
SmallVector<LocatorPathElt, 4 > path;
@@ -4951,7 +4959,7 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
4951
4959
const auto &solution = *entry.first ;
4952
4960
const auto *fix = entry.second ;
4953
4961
4954
- auto *locator = fix->getLocator ();
4962
+ auto *locator = getConstraintLocatorForAmbiguity ( fix->getLocator () );
4955
4963
4956
4964
if (locator->isForContextualType ()) {
4957
4965
contextualFixes.push_back ({&solution, fix});
@@ -5473,6 +5481,19 @@ void constraints::simplifyLocator(ASTNode &anchor,
5473
5481
}
5474
5482
break ;
5475
5483
5484
+ case ConstraintLocator::CoercionOperand: {
5485
+ auto *CE = castToExpr<CoerceExpr>(anchor);
5486
+ anchor = CE->getSubExpr ()->getValueProvidingExpr ();
5487
+ path = path.slice (1 );
5488
+ // When in a argument function type on a coercion context
5489
+ // look past the argument, because is just for identify the
5490
+ // argument type that is being matched.
5491
+ if (!path.empty () && path[0 ].is <LocatorPathElt::FunctionArgument>()) {
5492
+ path = path.slice (1 );
5493
+ }
5494
+ continue ;
5495
+ }
5496
+
5476
5497
case ConstraintLocator::GlobalActorType:
5477
5498
case ConstraintLocator::ContextualType: {
5478
5499
// This was just for identifying purposes, strip it off.
0 commit comments