@@ -8750,7 +8750,36 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
87508750 return SolutionKind::Solved;
87518751 }
87528752
8753- return matchExistentialTypes(type, protocol, kind, flags, locator);
8753+ auto result = matchExistentialTypes(type, protocol, kind, flags, locator);
8754+
8755+ if (shouldAttemptFixes() && result.isFailure()) {
8756+ auto *loc = getConstraintLocator(locator);
8757+
8758+ ArrayRef<LocatorPathElt> path = loc->getPath();
8759+ while (!path.empty()) {
8760+ if (!path.back().is<LocatorPathElt::InstanceType>())
8761+ break;
8762+
8763+ path = path.drop_back();
8764+ }
8765+
8766+ if (path.size() != loc->getPath().size()) {
8767+ loc = getConstraintLocator(loc->getAnchor(), path);
8768+ }
8769+
8770+ ConstraintFix *fix = nullptr;
8771+ if (loc->isLastElement<LocatorPathElt::ApplyArgToParam>()) {
8772+ fix = AllowArgumentMismatch::create(*this, type, protocol, loc);
8773+ } else if (loc->isLastElement<LocatorPathElt::ContextualType>()) {
8774+ fix = ContextualMismatch::create(*this, type, protocol, loc);
8775+ }
8776+
8777+ if (fix) {
8778+ return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
8779+ }
8780+ }
8781+
8782+ return result;
87548783}
87558784
87568785void ConstraintSystem::recordSynthesizedConformance(
@@ -9124,6 +9153,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
91249153 continue;
91259154 }
91269155
9156+ // Matching existentials could introduce constraints with `instance type`
9157+ // element at the end if the confirming type wasn't fully resolved.
9158+ if (path.back().is<LocatorPathElt::InstanceType>()) {
9159+ path.pop_back();
9160+ continue;
9161+ }
9162+
91279163 break;
91289164 }
91299165
@@ -9217,7 +9253,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
92179253 }
92189254 }
92199255
9220- if (loc->isLastElement <LocatorPathElt::MemberRefBase>()) {
9256+ if (path.back().is <LocatorPathElt::MemberRefBase>()) {
92219257 auto *fix = ContextualMismatch::create(*this, protocolTy, type, loc);
92229258 if (!recordFix(fix))
92239259 return SolutionKind::Solved;
@@ -9227,7 +9263,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
92279263 // for example to `AnyHashable`.
92289264 if ((kind == ConstraintKind::ConformsTo ||
92299265 kind == ConstraintKind::NonisolatedConformsTo) &&
9230- loc->isLastElement <LocatorPathElt::ApplyArgToParam>()) {
9266+ path.back().is <LocatorPathElt::ApplyArgToParam>()) {
92319267 auto *fix = AllowArgumentMismatch::create(*this, type, protocolTy, loc);
92329268 return recordFix(fix, /*impact=*/2) ? SolutionKind::Error
92339269 : SolutionKind::Solved;
0 commit comments