@@ -2616,11 +2616,22 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
2616
2616
if (!shouldAttemptFixes ())
2617
2617
return getTypeMatchFailure (locator);
2618
2618
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
+
2619
2628
// 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
2621
2630
// 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>()) {
2624
2635
auto *fix = AllowArgumentMismatch::create (
2625
2636
*this , type1, proto, getConstraintLocator (locator));
2626
2637
@@ -2643,21 +2654,19 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
2643
2654
//
2644
2655
// Once either reacher locators or better diagnostic presentation for
2645
2656
// nested type failures is available this check could be removed.
2646
- if (last-> is <LocatorPathElt::FunctionResult>())
2657
+ if (last. is <LocatorPathElt::FunctionResult>())
2647
2658
return getTypeMatchFailure (locator);
2648
2659
2649
2660
// If instance types didn't line up correctly, let's produce a
2650
2661
// diagnostic which mentions them together with their metatypes.
2651
- if (last-> is <LocatorPathElt::InstanceType>())
2662
+ if (last. is <LocatorPathElt::InstanceType>())
2652
2663
return getTypeMatchFailure (locator);
2653
2664
2654
2665
} else { // There are no elements in the path
2655
- auto anchor = locator.getAnchor ();
2656
2666
if (!(isExpr<AssignExpr>(anchor) || isExpr<CoerceExpr>(anchor)))
2657
2667
return getTypeMatchFailure (locator);
2658
2668
}
2659
2669
2660
- auto anchor = locator.getAnchor ();
2661
2670
if (isExpr<CoerceExpr>(anchor)) {
2662
2671
auto *fix = ContextualMismatch::create (
2663
2672
*this , type1, type2, getConstraintLocator (locator));
0 commit comments