Merge pull request #24097 from xedin/diag-mutating-getter-in-keypath

[ConstraintSystem] Detect and diagnoses use of members with mutating getters in key path
This commit is contained in:
Pavel Yaskevich
2019-04-18 13:12:22 -07:00
committed by GitHub
7 changed files with 164 additions and 45 deletions

View File

@@ -2453,9 +2453,8 @@ bool KeyPathSubscriptIndexHashableFailure::diagnoseAsError() {
return true;
}
bool InvalidStaticMemberRefInKeyPath::diagnoseAsError() {
SourceLoc InvalidMemberRefInKeyPath::getLoc() const {
auto *anchor = getRawAnchor();
auto loc = anchor->getLoc();
if (auto *KPE = dyn_cast<KeyPathExpr>(anchor)) {
auto *locator = getLocator();
@@ -2465,9 +2464,18 @@ bool InvalidStaticMemberRefInKeyPath::diagnoseAsError() {
});
assert(component != locator->getPath().end());
loc = KPE->getComponents()[component->getValue()].getLoc();
return KPE->getComponents()[component->getValue()].getLoc();
}
emitDiagnostic(loc, diag::expr_keypath_static_member, Member->getBaseName());
return anchor->getLoc();
}
bool InvalidStaticMemberRefInKeyPath::diagnoseAsError() {
emitDiagnostic(getLoc(), diag::expr_keypath_static_member, getName());
return true;
}
bool InvalidMemberWithMutatingGetterInKeyPath::diagnoseAsError() {
emitDiagnostic(getLoc(), diag::expr_keypath_mutating_getter, getName());
return true;
}