mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #38199 from xedin/rdar-65667992
[ConstraintSystem] Bind missing member in pattern match to a hole early
This commit is contained in:
@@ -4887,14 +4887,24 @@ bool ConstraintSystem::repairFailures(
|
||||
}
|
||||
|
||||
case ConstraintLocator::PatternMatch: {
|
||||
auto *pattern = elt.castTo<LocatorPathElt::PatternMatch>().getPattern();
|
||||
bool isMemberMatch =
|
||||
lhs->is<FunctionType>() && isa<EnumElementPattern>(pattern);
|
||||
|
||||
// If member reference couldn't be resolved, let's allow pattern
|
||||
// to have holes.
|
||||
if (rhs->isPlaceholder() && isMemberMatch) {
|
||||
recordAnyTypeVarAsPotentialHole(lhs);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If either type is a placeholder, consider this fixed.
|
||||
if (lhs->isPlaceholder() || rhs->isPlaceholder())
|
||||
return true;
|
||||
|
||||
// If the left-hand side is a function type and the pattern is an enum
|
||||
// element pattern, call it a contextual mismatch.
|
||||
auto pattern = elt.castTo<LocatorPathElt::PatternMatch>().getPattern();
|
||||
if (lhs->is<FunctionType>() && isa<EnumElementPattern>(pattern)) {
|
||||
// If member reference didn't match expected pattern,
|
||||
// let's consider that a contextual mismatch.
|
||||
if (isMemberMatch) {
|
||||
recordAnyTypeVarAsPotentialHole(lhs);
|
||||
recordAnyTypeVarAsPotentialHole(rhs);
|
||||
|
||||
@@ -8207,6 +8217,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
|
||||
// `key path` constraint can't be retired until all components
|
||||
// are simplified.
|
||||
addTypeVariableConstraintsToWorkList(memberTypeVar);
|
||||
} else if (locator->isLastElement<LocatorPathElt::PatternMatch>()) {
|
||||
// Let's handle member patterns specifically because they use
|
||||
// equality instead of argument application constraint, so allowing
|
||||
// them to bind member could mean missing valid hole positions in
|
||||
// the pattern.
|
||||
assignFixedType(memberTypeVar,
|
||||
PlaceholderType::get(getASTContext(), memberTypeVar));
|
||||
} else {
|
||||
recordPotentialHole(memberTypeVar);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user