@@ -2616,11 +2616,22 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
26162616 if (!shouldAttemptFixes ())
26172617 return getTypeMatchFailure (locator);
26182618
2619+ SmallVector<LocatorPathElt, 4 > path;
2620+ auto anchor = locator.getLocatorParts (path);
2621+
2622+ // If the path ends at `optional payload` it means that this
2623+ // check is part of an implicit value-to-optional conversion,
2624+ // and it could be safely dropped.
2625+ if (!path.empty () && path.back ().is <LocatorPathElt::OptionalPayload>())
2626+ path.pop_back ();
2627+
26192628 // Determine whether this conformance mismatch is
2620- // associate with argument to a call, and if so
2629+ // associated with argument to a call, and if so
26212630 // produce a tailored fix.
2622- if (auto last = locator.last ()) {
2623- if (last->is <LocatorPathElt::ApplyArgToParam>()) {
2631+ if (!path.empty ()) {
2632+ auto last = path.back ();
2633+
2634+ if (last.is <LocatorPathElt::ApplyArgToParam>()) {
26242635 auto *fix = AllowArgumentMismatch::create (
26252636 *this , type1, proto, getConstraintLocator (locator));
26262637
@@ -2643,21 +2654,19 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
26432654 //
26442655 // Once either reacher locators or better diagnostic presentation for
26452656 // nested type failures is available this check could be removed.
2646- if (last-> is <LocatorPathElt::FunctionResult>())
2657+ if (last. is <LocatorPathElt::FunctionResult>())
26472658 return getTypeMatchFailure (locator);
26482659
26492660 // If instance types didn't line up correctly, let's produce a
26502661 // diagnostic which mentions them together with their metatypes.
2651- if (last-> is <LocatorPathElt::InstanceType>())
2662+ if (last. is <LocatorPathElt::InstanceType>())
26522663 return getTypeMatchFailure (locator);
26532664
26542665 } else { // There are no elements in the path
2655- auto anchor = locator.getAnchor ();
26562666 if (!(isExpr<AssignExpr>(anchor) || isExpr<CoerceExpr>(anchor)))
26572667 return getTypeMatchFailure (locator);
26582668 }
26592669
2660- auto anchor = locator.getAnchor ();
26612670 if (isExpr<CoerceExpr>(anchor)) {
26622671 auto *fix = ContextualMismatch::create (
26632672 *this , type1, type2, getConstraintLocator (locator));
0 commit comments