@@ -8750,7 +8750,36 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8750
8750
return SolutionKind::Solved;
8751
8751
}
8752
8752
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;
8754
8783
}
8755
8784
8756
8785
void ConstraintSystem::recordSynthesizedConformance(
@@ -9124,6 +9153,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
9124
9153
continue;
9125
9154
}
9126
9155
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
+
9127
9163
break;
9128
9164
}
9129
9165
@@ -9217,7 +9253,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
9217
9253
}
9218
9254
}
9219
9255
9220
- if (loc->isLastElement <LocatorPathElt::MemberRefBase>()) {
9256
+ if (path.back().is <LocatorPathElt::MemberRefBase>()) {
9221
9257
auto *fix = ContextualMismatch::create(*this, protocolTy, type, loc);
9222
9258
if (!recordFix(fix))
9223
9259
return SolutionKind::Solved;
@@ -9227,7 +9263,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
9227
9263
// for example to `AnyHashable`.
9228
9264
if ((kind == ConstraintKind::ConformsTo ||
9229
9265
kind == ConstraintKind::NonisolatedConformsTo) &&
9230
- loc->isLastElement <LocatorPathElt::ApplyArgToParam>()) {
9266
+ path.back().is <LocatorPathElt::ApplyArgToParam>()) {
9231
9267
auto *fix = AllowArgumentMismatch::create(*this, type, protocolTy, loc);
9232
9268
return recordFix(fix, /*impact=*/2) ? SolutionKind::Error
9233
9269
: SolutionKind::Solved;
0 commit comments