[Sema] Diagnose method arg captures that are not Hashable/Equatable.

This commit is contained in:
Amritpan Kaur
2025-01-16 19:07:00 -08:00
parent 970159c09d
commit a96b780a28
6 changed files with 36 additions and 8 deletions

View File

@@ -607,6 +607,25 @@ bool ConstraintLocator::isKeyPathSubscriptComponent() const {
});
}
bool ConstraintLocator::isKeyPathMemberComponent() const {
auto *anchor = getAsExpr(getAnchor());
auto *KPE = dyn_cast_or_null<KeyPathExpr>(anchor);
if (!KPE)
return false;
using ComponentKind = KeyPathExpr::Component::Kind;
return llvm::any_of(getPath(), [&](const LocatorPathElt &elt) {
auto keyPathElt = elt.getAs<LocatorPathElt::KeyPathComponent>();
if (!keyPathElt)
return false;
auto index = keyPathElt->getIndex();
auto &component = KPE->getComponents()[index];
return component.getKind() == ComponentKind::Member ||
component.getKind() == ComponentKind::UnresolvedMember;
});
}
bool ConstraintLocator::isForKeyPathDynamicMemberLookup() const {
auto path = getPath();
return !path.empty() && path.back().isKeyPathDynamicMember();