Skip to content

Commit 005809d

Browse files
committed
Significantly simplify noteTargetOfDiagnostic by cutting it off of
resolveLocatorToDecl entirely. Rename it to noteTargetOfMissingArchetype. NFC.
1 parent e901bd0 commit 005809d

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -379,38 +379,40 @@ ConcreteDeclRef constraints::resolveLocatorToDecl(
379379

380380
/// Emit a note referring to the target of a diagnostic, e.g., the function
381381
/// or parameter being used.
382-
static void noteTargetOfDiagnostic(ConstraintSystem &cs,
383-
ConstraintLocator *targetLocator) {
384-
// If there's no anchor, there's nothing we can do.
385-
if (!targetLocator->getAnchor())
386-
return;
382+
static void noteTargetOfMissingArchetype(ConstraintSystem &cs,
383+
ConstraintLocator *targetLocator) {
387384

388-
// Try to resolve the locator to a particular declaration.
389-
auto resolved
390-
= resolveLocatorToDecl(cs, targetLocator,
391-
[&](ConstraintLocator *locator) -> Optional<SelectedOverload> {
392-
return None;
393-
},
394-
[&](ValueDecl *decl, Type openedType) -> ConcreteDeclRef {
395-
return decl;
396-
});
385+
auto anchor = targetLocator->getAnchor();
386+
if (!anchor) return;
387+
388+
ConcreteDeclRef resolved;
389+
390+
// Simple case: direct reference to a declaration.
391+
if (auto dre = dyn_cast<DeclRefExpr>(anchor))
392+
resolved = dre->getDeclRef();
393+
394+
// Simple case: direct reference to a declaration.
395+
if (auto mre = dyn_cast<MemberRefExpr>(anchor))
396+
resolved = mre->getMember();
397+
398+
if (auto ctorRef = dyn_cast<OtherConstructorDeclRefExpr>(anchor))
399+
resolved = ctorRef->getDeclRef();
397400

398401
// We couldn't resolve the locator to a declaration, so we're done.
399402
if (!resolved)
400403
return;
401-
404+
402405
auto decl = resolved.getDecl();
403406
if (isa<FuncDecl>(decl)) {
404407
auto name = decl->getName();
405-
cs.getTypeChecker().diagnose(decl,
406-
name.isOperator()? diag::note_call_to_operator
407-
: diag::note_call_to_func,
408-
name);
408+
auto diagID = name.isOperator() ? diag::note_call_to_operator
409+
: diag::note_call_to_func;
410+
cs.getTypeChecker().diagnose(decl, diagID, name);
409411
return;
410412
}
411413

414+
// FIXME: Specialize for implicitly-generated constructors.
412415
if (isa<ConstructorDecl>(decl)) {
413-
// FIXME: Specialize for implicitly-generated constructors.
414416
cs.getTypeChecker().diagnose(decl, diag::note_call_to_initializer);
415417
return;
416418
}
@@ -4854,7 +4856,7 @@ void FailureDiagnosis::diagnoseAmbiguity(Expr *E) {
48544856
diagnose(expr->getLoc(), diag::unbound_generic_parameter, archetype);
48554857

48564858
// Emit a "note, archetype declared here" sort of thing.
4857-
noteTargetOfDiagnostic(*CS, tv->getImpl().getLocator());
4859+
noteTargetOfMissingArchetype(*CS, tv->getImpl().getLocator());
48584860
return;
48594861
}
48604862
continue;

0 commit comments

Comments
 (0)