Skip to content

Commit 3ee4668

Browse files
committed
[CodeComplete] Fix a nullptr crash
If `FuncDeclRef` is `null` we shouldn’t be trying to get any parameters from it.
1 parent 89b9e48 commit 3ee4668

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/IDE/ArgumentCompletion.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ bool ArgumentTypeCheckCompletionCallback::addPossibleParams(
5353
// Since not all function types are backed by declarations (e.g. closure
5454
// paramters), `DeclParam` might be `nullptr`.
5555
const AnyFunctionType::Param *TypeParam = &ParamsToPass[Idx];
56-
const ParamDecl *DeclParam = getParameterAt(Res.FuncDeclRef, Idx);
56+
const ParamDecl *DeclParam = nullptr;
57+
if (Res.FuncDeclRef) {
58+
DeclParam = getParameterAt(Res.FuncDeclRef, Idx);
59+
}
5760

5861
bool Required = true;
5962
if (DeclParam && DeclParam->isDefaultArgument()) {

test/IDE/complete_call_pattern_heuristics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ func testArg2Name3() {
3434
// LABELED_FIRSTARG-DAG: Pattern/Local/Flair[ArgLabels]: {#arg1: Int#}[#Int#];
3535
// LABELED_FIRSTARG-NOT: ['(']{#arg1: Int#}, {#arg2: Int#}[')'][#Void#];
3636

37+
func subscriptAccess(info: [String: Int]) {
38+
info[#^SUBSCRIPT_ACCESS^#]
39+
// SUBSCRIPT_ACCESS: Pattern/Local/Flair[ArgLabels]: {#keyPath: KeyPath<[String : Int], Value>#}[#KeyPath<[String : Int], Value>#]; name=keyPath:
40+
}

0 commit comments

Comments
 (0)