[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

@@ -6347,7 +6347,8 @@ bool AnyObjectKeyPathRootFailure::diagnoseAsError() {
SourceLoc KeyPathSubscriptIndexHashableFailure::getLoc() const {
auto *locator = getLocator();
if (locator->isKeyPathSubscriptComponent()) {
if (locator->isKeyPathSubscriptComponent() ||
locator->isKeyPathMemberComponent()) {
auto *KPE = castToExpr<KeyPathExpr>(getAnchor());
if (auto kpElt = locator->findFirst<LocatorPathElt::KeyPathComponent>())
return KPE->getComponents()[kpElt->getIndex()].getLoc();
@@ -6357,7 +6358,9 @@ SourceLoc KeyPathSubscriptIndexHashableFailure::getLoc() const {
}
bool KeyPathSubscriptIndexHashableFailure::diagnoseAsError() {
emitDiagnostic(diag::expr_keypath_subscript_index_not_hashable,
auto *locator = getLocator();
emitDiagnostic(diag::expr_keypath_arg_or_index_not_hashable,
!locator->isKeyPathMemberComponent(),
resolveType(NonConformingType));
return true;
}