@@ -379,38 +379,40 @@ ConcreteDeclRef constraints::resolveLocatorToDecl(
379
379
380
380
// / Emit a note referring to the target of a diagnostic, e.g., the function
381
381
// / 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) {
387
384
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 ();
397
400
398
401
// We couldn't resolve the locator to a declaration, so we're done.
399
402
if (!resolved)
400
403
return ;
401
-
404
+
402
405
auto decl = resolved.getDecl ();
403
406
if (isa<FuncDecl>(decl)) {
404
407
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);
409
411
return ;
410
412
}
411
413
414
+ // FIXME: Specialize for implicitly-generated constructors.
412
415
if (isa<ConstructorDecl>(decl)) {
413
- // FIXME: Specialize for implicitly-generated constructors.
414
416
cs.getTypeChecker ().diagnose (decl, diag::note_call_to_initializer);
415
417
return ;
416
418
}
@@ -4854,7 +4856,7 @@ void FailureDiagnosis::diagnoseAmbiguity(Expr *E) {
4854
4856
diagnose (expr->getLoc (), diag::unbound_generic_parameter, archetype);
4855
4857
4856
4858
// Emit a "note, archetype declared here" sort of thing.
4857
- noteTargetOfDiagnostic (*CS, tv->getImpl ().getLocator ());
4859
+ noteTargetOfMissingArchetype (*CS, tv->getImpl ().getLocator ());
4858
4860
return ;
4859
4861
}
4860
4862
continue ;
0 commit comments