Skip to content

Commit 2d7dbd3

Browse files
committed
[CodeCompletion] Check if type is function before making call pattern suggestions
1 parent 0804105 commit 2d7dbd3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/IDE/ArgumentCompletion.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,16 @@ void ArgumentTypeCheckCompletionCallback::deliverResults(
250250
}
251251
}
252252
if (Result.FuncTy) {
253-
if (Result.IsSubscript) {
254-
assert(SemanticContext != SemanticContextKind::None);
255-
auto *SD = dyn_cast_or_null<SubscriptDecl>(Result.FuncD);
256-
Lookup.addSubscriptCallPattern(
257-
Result.FuncTy->getAs<AnyFunctionType>(), SD, SemanticContext);
258-
} else {
259-
auto *FD = dyn_cast_or_null<AbstractFunctionDecl>(Result.FuncD);
260-
Lookup.addFunctionCallPattern(Result.FuncTy->getAs<AnyFunctionType>(),
261-
FD, SemanticContext);
253+
if (auto FuncTy = Result.FuncTy->lookThroughAllOptionalTypes()
254+
->getAs<AnyFunctionType>()) {
255+
if (Result.IsSubscript) {
256+
assert(SemanticContext != SemanticContextKind::None);
257+
auto *SD = dyn_cast_or_null<SubscriptDecl>(Result.FuncD);
258+
Lookup.addSubscriptCallPattern(FuncTy, SD, SemanticContext);
259+
} else {
260+
auto *FD = dyn_cast_or_null<AbstractFunctionDecl>(Result.FuncD);
261+
Lookup.addFunctionCallPattern(FuncTy, FD, SemanticContext);
262+
}
262263
}
263264
}
264265
}

0 commit comments

Comments
 (0)