Skip to content

Commit 557505d

Browse files
committed
[CodeCompletion] Look through ApplyExpr to get referenced decl
For example: let x: MyClass = .create(<#COMPLETE#>) This expression ends up with: (call_expr (dot_syntax_self_apply_expr (decl_ref_expr decl='C.create(_:arg1)' (type_expr type=MyClass)))) So we need to look through 'DotSyntaxSelfApplyExpr' to get the decl.
1 parent 5b5d342 commit 557505d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ static bool collectPossibleCalleesForApply(
352352
auto *fnExpr = callExpr->getFn();
353353

354354
if (auto type = fnExpr->getType()) {
355-
if (auto *funcType = type->getAs<AnyFunctionType>())
356-
candidates.emplace_back(funcType, fnExpr->getReferencedDecl().getDecl());
355+
if (auto *funcType = type->getAs<AnyFunctionType>()) {
356+
auto refDecl = fnExpr->getReferencedDecl();
357+
if (!refDecl)
358+
if (auto apply = dyn_cast<ApplyExpr>(fnExpr))
359+
refDecl = apply->getFn()->getReferencedDecl();
360+
candidates.emplace_back(funcType, refDecl.getDecl());
361+
}
357362
} else if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
358363
if (auto *decl = DRE->getDecl()) {
359364
auto declType = decl->getInterfaceType();

0 commit comments

Comments
 (0)