Skip to content

Commit 57c7702

Browse files
committed
[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.
1 parent bdd68df commit 57c7702

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6243,7 +6243,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
62436243
auto subflags = getDefaultDecompositionOptions(flags);
62446244
// The constraint ought to have been anchored on a KeyPathExpr.
62456245
auto keyPath = cast<KeyPathExpr>(locator.getBaseLocator()->getAnchor());
6246-
6246+
62476247
// Gather overload choices for any key path components associated with this
62486248
// key path.
62496249
SmallVector<OverloadChoice, 4> choices;
@@ -6352,6 +6352,25 @@ ConstraintSystem::simplifyKeyPathConstraint(
63526352
anyComponentsUnresolved = true;
63536353
continue;
63546354
}
6355+
6356+
if (shouldAttemptFixes()) {
6357+
auto *componentLoc = getConstraintLocator(
6358+
keyPath, {LocatorPathElt::KeyPathComponent(i),
6359+
LocatorPathElt::KeyPathComponentResult()});
6360+
6361+
// If one of the components haven't been resolved, let's check
6362+
// whether it has been determined to be a "hole" and if so,
6363+
// let's allow component validation to contiunue.
6364+
//
6365+
// This helps to, for example, diagnose problems with missing
6366+
// members used as part of a key path.
6367+
if (isHoleAt(componentLoc)) {
6368+
anyComponentsUnresolved = true;
6369+
capability = ReadOnly;
6370+
continue;
6371+
}
6372+
}
6373+
63556374
return SolutionKind::Unsolved;
63566375
}
63576376

0 commit comments

Comments
 (0)