Skip to content

Commit 0923229

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. (cherry picked from commit 557505d)
1 parent f06194b commit 0923229

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
@@ -399,8 +399,13 @@ bool collectPossibleCalleesForApply(
399399
auto *fnExpr = callExpr->getFn();
400400

401401
if (auto type = fnExpr->getType()) {
402-
if (auto *funcType = type->getAs<AnyFunctionType>())
403-
candidates.emplace_back(funcType, fnExpr->getReferencedDecl().getDecl());
402+
if (auto *funcType = type->getAs<AnyFunctionType>()) {
403+
auto refDecl = fnExpr->getReferencedDecl();
404+
if (!refDecl)
405+
if (auto apply = dyn_cast<ApplyExpr>(fnExpr))
406+
refDecl = apply->getFn()->getReferencedDecl();
407+
candidates.emplace_back(funcType, refDecl.getDecl());
408+
}
404409
} else if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
405410
if (auto *decl = DRE->getDecl()) {
406411
auto declType = decl->getInterfaceType();

0 commit comments

Comments
 (0)