mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #30578 from AnthonyLatsis/memb-fail-qoi
[DiagQoI] Improve fallback fixits for static member on instance errors
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user