mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Diagnostics] Add a workaround for inability to diagnose name shadowing
Let's cover at least the most common cases - min/max. Fixing the problem requires refactoring of `resolveDeclRefExpr`.
This commit is contained in:
@@ -499,6 +499,26 @@ bool RemoveExtraneousArguments::diagnose(Expr *root, bool asNote) const {
|
||||
return failure.diagnose(asNote);
|
||||
}
|
||||
|
||||
bool RemoveExtraneousArguments::isMinMaxNameShadowing(
|
||||
ConstraintSystem &cs, ConstraintLocatorBuilder locator) {
|
||||
auto *anchor = dyn_cast_or_null<CallExpr>(locator.getAnchor());
|
||||
if (!anchor)
|
||||
return false;
|
||||
|
||||
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(anchor->getFn())) {
|
||||
if (auto *baseExpr = dyn_cast<DeclRefExpr>(UDE->getBase())) {
|
||||
auto *decl = baseExpr->getDecl();
|
||||
if (baseExpr->isImplicit() && decl &&
|
||||
decl->getFullName() == cs.getASTContext().Id_self) {
|
||||
auto memberName = UDE->getName();
|
||||
return memberName.isSimpleName("min") || memberName.isSimpleName("max");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
RemoveExtraneousArguments *RemoveExtraneousArguments::create(
|
||||
ConstraintSystem &cs, FunctionType *contextualType,
|
||||
llvm::ArrayRef<IndexedParam> extraArgs, ConstraintLocator *locator) {
|
||||
|
||||
Reference in New Issue
Block a user