mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintSystem] Detect and diagnose missing member refs in key path
Key path components can reference an invalid or missing member just like regular expressions, so we need to account for that while trying to simplify key path constraint.
This commit is contained in:
@@ -6243,7 +6243,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
|
||||
auto subflags = getDefaultDecompositionOptions(flags);
|
||||
// The constraint ought to have been anchored on a KeyPathExpr.
|
||||
auto keyPath = cast<KeyPathExpr>(locator.getBaseLocator()->getAnchor());
|
||||
|
||||
|
||||
// Gather overload choices for any key path components associated with this
|
||||
// key path.
|
||||
SmallVector<OverloadChoice, 4> choices;
|
||||
@@ -6352,6 +6352,25 @@ ConstraintSystem::simplifyKeyPathConstraint(
|
||||
anyComponentsUnresolved = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (shouldAttemptFixes()) {
|
||||
auto *componentLoc = getConstraintLocator(
|
||||
keyPath, {LocatorPathElt::KeyPathComponent(i),
|
||||
LocatorPathElt::KeyPathComponentResult()});
|
||||
|
||||
// If one of the components haven't been resolved, let's check
|
||||
// whether it has been determined to be a "hole" and if so,
|
||||
// let's allow component validation to contiunue.
|
||||
//
|
||||
// This helps to, for example, diagnose problems with missing
|
||||
// members used as part of a key path.
|
||||
if (isHoleAt(componentLoc)) {
|
||||
anyComponentsUnresolved = true;
|
||||
capability = ReadOnly;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return SolutionKind::Unsolved;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user