Merge pull request #30578 from AnthonyLatsis/memb-fail-qoi

[DiagQoI] Improve fallback fixits for static member on instance errors
This commit is contained in:
Anthony Latsis
2020-03-23 19:31:10 +03:00
committed by GitHub
4 changed files with 29 additions and 12 deletions

View File

@@ -3710,15 +3710,19 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
}
// Fall back to a fix-it with a full type qualifier
if (auto *NTD = Member->getDeclContext()->getSelfNominalTypeDecl()) {
auto type = NTD->getSelfInterfaceType();
if (auto *SE = dyn_cast<SubscriptExpr>(getRawAnchor())) {
auto *baseExpr = SE->getBase();
Diag->fixItReplace(baseExpr->getSourceRange(), diag::replace_with_type,
type);
} else {
Diag->fixItInsert(loc, diag::insert_type_qualification, type);
}
const Expr *baseExpr = nullptr;
if (const auto SE = dyn_cast<SubscriptExpr>(getRawAnchor()))
baseExpr = SE->getBase();
else if (const auto UDE = dyn_cast<UnresolvedDotExpr>(getRawAnchor()))
baseExpr = UDE->getBase();
// An implicit 'self' reference base expression means we should
// prepend with qualification.
if (baseExpr && !baseExpr->isImplicit()) {
Diag->fixItReplace(baseExpr->getSourceRange(),
diag::replace_with_type, baseTy);
} else {
Diag->fixItInsert(loc, diag::insert_type_qualification, baseTy);
}
return true;