@@ -4878,14 +4878,24 @@ bool ConstraintSystem::repairFailures(
4878
4878
}
4879
4879
4880
4880
case ConstraintLocator::PatternMatch: {
4881
+ auto *pattern = elt.castTo <LocatorPathElt::PatternMatch>().getPattern ();
4882
+ bool isMemberMatch =
4883
+ lhs->is <FunctionType>() && isa<EnumElementPattern>(pattern);
4884
+
4885
+ // If member reference couldn't be resolved, let's allow pattern
4886
+ // to have holes.
4887
+ if (rhs->isPlaceholder () && isMemberMatch) {
4888
+ markAnyTypeVarsAsPotentialHoles (lhs);
4889
+ return true ;
4890
+ }
4891
+
4881
4892
// If either type is a placeholder, consider this fixed.
4882
4893
if (lhs->isPlaceholder () || rhs->isPlaceholder ())
4883
4894
return true ;
4884
4895
4885
- // If the left-hand side is a function type and the pattern is an enum
4886
- // element pattern, call it a contextual mismatch.
4887
- auto pattern = elt.castTo <LocatorPathElt::PatternMatch>().getPattern ();
4888
- if (lhs->is <FunctionType>() && isa<EnumElementPattern>(pattern)) {
4896
+ // If member reference didn't match expected pattern,
4897
+ // let's consider that a contextual mismatch.
4898
+ if (isMemberMatch) {
4889
4899
markAnyTypeVarsAsPotentialHoles (lhs);
4890
4900
markAnyTypeVarsAsPotentialHoles (rhs);
4891
4901
@@ -8189,6 +8199,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
8189
8199
// `key path` constraint can't be retired until all components
8190
8200
// are simplified.
8191
8201
addTypeVariableConstraintsToWorkList (memberTypeVar);
8202
+ } else if (locator->isLastElement <LocatorPathElt::PatternMatch>()) {
8203
+ // Let's handle member patterns specifically because they use
8204
+ // equality instead of argument application constraint, so allowing
8205
+ // them to bind member could mean missing valid hole positions in
8206
+ // the pattern.
8207
+ assignFixedType (memberTypeVar,
8208
+ PlaceholderType::get (getASTContext (), memberTypeVar));
8192
8209
} else {
8193
8210
recordPotentialHole (memberTypeVar);
8194
8211
}
0 commit comments