@@ -289,20 +289,6 @@ static Expr *simplifyLocatorToAnchor(ConstraintSystem &cs,
289
289
return locator->getAnchor ();
290
290
}
291
291
292
- // / Retrieve the argument pattern for the given declaration.
293
- // /
294
- static ParameterList *getParameterList (ValueDecl *decl) {
295
- if (auto func = dyn_cast<FuncDecl>(decl))
296
- return func->getParameterList (0 );
297
- if (auto constructor = dyn_cast<ConstructorDecl>(decl))
298
- return constructor->getParameterList (1 );
299
- if (auto subscript = dyn_cast<SubscriptDecl>(decl))
300
- return subscript->getIndices ();
301
-
302
- // FIXME: Variables of function type?
303
- return nullptr ;
304
- }
305
-
306
292
ConcreteDeclRef constraints::resolveLocatorToDecl (
307
293
ConstraintSystem &cs,
308
294
ConstraintLocator *locator,
@@ -314,7 +300,6 @@ ConcreteDeclRef constraints::resolveLocatorToDecl(
314
300
if (!locator->getAnchor ())
315
301
return ConcreteDeclRef ();
316
302
317
- ConcreteDeclRef declRef;
318
303
auto anchor = locator->getAnchor ();
319
304
// Unwrap any specializations, constructor calls, implicit conversions, and
320
305
// '.'s.
@@ -355,79 +340,41 @@ ConcreteDeclRef constraints::resolveLocatorToDecl(
355
340
break ;
356
341
} while (true );
357
342
358
- auto getConcreteDeclRefFromOverload
359
- = [&](const SelectedOverload &selected) -> ConcreteDeclRef {
360
- return getConcreteDeclRef (selected.choice .getDecl (),
361
- selected.openedType );
362
- };
343
+ // Simple case: direct reference to a declaration.
344
+ if (auto dre = dyn_cast<DeclRefExpr>(anchor))
345
+ return dre->getDeclRef ();
346
+
347
+ // Simple case: direct reference to a declaration.
348
+ if (auto mre = dyn_cast<MemberRefExpr>(anchor))
349
+ return mre->getMember ();
363
350
364
- if (auto dre = dyn_cast<DeclRefExpr>(anchor)) {
365
- // Simple case: direct reference to a declaration.
366
- declRef = dre->getDeclRef ();
367
- } else if (auto mre = dyn_cast<MemberRefExpr>(anchor)) {
368
- // Simple case: direct reference to a declaration.
369
- declRef = mre->getMember ();
370
- } else if (isa<OverloadedDeclRefExpr>(anchor) ||
371
- isa<OverloadedMemberRefExpr>(anchor) ||
372
- isa<UnresolvedDeclRefExpr>(anchor)) {
351
+ if (auto ctorRef = dyn_cast<OtherConstructorDeclRefExpr>(anchor))
352
+ return ctorRef->getDeclRef ();
353
+
354
+ if (isa<OverloadedDeclRefExpr>(anchor) ||
355
+ isa<OverloadedMemberRefExpr>(anchor) ||
356
+ isa<UnresolvedDeclRefExpr>(anchor)) {
373
357
// Overloaded and unresolved cases: find the resolved overload.
374
358
auto anchorLocator = cs.getConstraintLocator (anchor);
375
359
if (auto selected = findOvlChoice (anchorLocator)) {
376
360
if (selected->choice .isDecl ())
377
- declRef = getConcreteDeclRefFromOverload (*selected);
361
+ return getConcreteDeclRef (selected->choice .getDecl (),
362
+ selected->openedType );
378
363
}
379
- } else if (isa<UnresolvedMemberExpr>(anchor)) {
364
+ }
365
+
366
+ if (isa<UnresolvedMemberExpr>(anchor)) {
380
367
// Unresolved member: find the resolved overload.
381
- auto anchorLocator = cs.getConstraintLocator (
382
- anchor,
368
+ auto anchorLocator = cs.getConstraintLocator (anchor,
383
369
ConstraintLocator::UnresolvedMember);
384
370
if (auto selected = findOvlChoice (anchorLocator)) {
385
371
if (selected->choice .isDecl ())
386
- declRef = getConcreteDeclRefFromOverload (*selected);
372
+ return getConcreteDeclRef (selected->choice .getDecl (),
373
+ selected->openedType );
387
374
}
388
- } else if (auto ctorRef = dyn_cast<OtherConstructorDeclRefExpr>(anchor)) {
389
- declRef = ctorRef->getDeclRef ();
390
375
}
391
376
392
- // If we didn't find the declaration, we're out of luck.
393
- if (!declRef)
394
- return ConcreteDeclRef ();
395
-
396
- // Use the declaration and the path to produce a more specific result.
397
- // FIXME: This is an egregious hack. We'd be far better off
398
- // FIXME: Perform deeper path resolution?
399
- auto path = locator->getPath ();
400
- ParameterList *parameterList = nullptr ;
401
- bool impliesFullPattern = false ;
402
- while (!path.empty ()) {
403
- switch (path[0 ].getKind ()) {
404
- case ConstraintLocator::ApplyArgument:
405
- // If we're calling into something that has parameters, dig into the
406
- // actual parameter pattern.
407
- parameterList = getParameterList (declRef.getDecl ());
408
- if (!parameterList)
409
- break ;
410
-
411
- impliesFullPattern = true ;
412
- path = path.slice (1 );
413
- continue ;
414
-
415
- case ConstraintLocator::ApplyArgToParam: {
416
- if (!parameterList) break ;
417
-
418
- unsigned index = path[0 ].getValue2 ();
419
- if (index < parameterList->size ())
420
- return parameterList->get (index);
421
- break ;
422
- }
423
-
424
- default :
425
- break ;
426
- }
427
-
428
- break ;
429
- }
430
- return declRef;
377
+ return ConcreteDeclRef ();
431
378
}
432
379
433
380
// / Emit a note referring to the target of a diagnostic, e.g., the function
0 commit comments