@@ -4887,14 +4887,24 @@ bool ConstraintSystem::repairFailures(
4887
4887
}
4888
4888
4889
4889
case ConstraintLocator::PatternMatch: {
4890
+ auto *pattern = elt.castTo <LocatorPathElt::PatternMatch>().getPattern ();
4891
+ bool isMemberMatch =
4892
+ lhs->is <FunctionType>() && isa<EnumElementPattern>(pattern);
4893
+
4894
+ // If member reference couldn't be resolved, let's allow pattern
4895
+ // to have holes.
4896
+ if (rhs->isPlaceholder () && isMemberMatch) {
4897
+ recordAnyTypeVarAsPotentialHole (lhs);
4898
+ return true ;
4899
+ }
4900
+
4890
4901
// If either type is a placeholder, consider this fixed.
4891
4902
if (lhs->isPlaceholder () || rhs->isPlaceholder ())
4892
4903
return true ;
4893
4904
4894
- // If the left-hand side is a function type and the pattern is an enum
4895
- // element pattern, call it a contextual mismatch.
4896
- auto pattern = elt.castTo <LocatorPathElt::PatternMatch>().getPattern ();
4897
- if (lhs->is <FunctionType>() && isa<EnumElementPattern>(pattern)) {
4905
+ // If member reference didn't match expected pattern,
4906
+ // let's consider that a contextual mismatch.
4907
+ if (isMemberMatch) {
4898
4908
recordAnyTypeVarAsPotentialHole (lhs);
4899
4909
recordAnyTypeVarAsPotentialHole (rhs);
4900
4910
@@ -8207,6 +8217,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
8207
8217
// `key path` constraint can't be retired until all components
8208
8218
// are simplified.
8209
8219
addTypeVariableConstraintsToWorkList (memberTypeVar);
8220
+ } else if (locator->isLastElement <LocatorPathElt::PatternMatch>()) {
8221
+ // Let's handle member patterns specifically because they use
8222
+ // equality instead of argument application constraint, so allowing
8223
+ // them to bind member could mean missing valid hole positions in
8224
+ // the pattern.
8225
+ assignFixedType (memberTypeVar,
8226
+ PlaceholderType::get (getASTContext (), memberTypeVar));
8210
8227
} else {
8211
8228
recordPotentialHole (memberTypeVar);
8212
8229
}
0 commit comments