mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fix indexing constructors with generic parameters (#65597)
Previously in the case of a constructor like `A<Int>(value: 1)` `Fn->getLoc()` returned the location of `>(value: 1)` while the actual location we're looking for is correctly the start of `A<Int>(value: 1)`. This adjusts the location we're looking up to use the start location of the constructor instead. Fixes: https://github.com/apple/swift/issues/54532
This commit is contained in:
@@ -827,9 +827,22 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
|
||||
|
||||
if (auto *TD = dyn_cast<TypeDecl>(D)) {
|
||||
if (!CtorRefs.empty() && BaseNameLoc.isValid()) {
|
||||
Expr *Fn = CtorRefs.back()->getFn();
|
||||
if (Fn->getLoc() == BaseNameLoc) {
|
||||
D = ide::getReferencedDecl(Fn).second.getDecl();
|
||||
ConstructorRefCallExpr *Ctor = CtorRefs.back();
|
||||
SourceLoc CtorLoc = Ctor->getFn()->getLoc();
|
||||
// Get the location of the type, ignoring parens, rather than the start of
|
||||
// the Expr, to match the lookup.
|
||||
if (auto *TE = dyn_cast<TypeExpr>(Ctor->getBase()))
|
||||
CtorLoc = TE->getTypeRepr()->getWithoutParens()->getLoc();
|
||||
|
||||
bool isImplicit = false;
|
||||
Expr *Fn = Ctor->getFn();
|
||||
while (auto *ICE = dyn_cast<ImplicitConversionExpr>(Fn))
|
||||
Fn = ICE->getSubExpr();
|
||||
if (auto *DRE = dyn_cast<DeclRefExpr>(Fn))
|
||||
isImplicit = DRE->isImplicit();
|
||||
|
||||
if (isImplicit && CtorLoc == BaseNameLoc) {
|
||||
D = ide::getReferencedDecl(Ctor->getFn()).second.getDecl();
|
||||
if (D == nullptr) {
|
||||
assert(false && "Unhandled constructor reference");
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user