Skip to content

Commit 31f0f28

Browse files
authored
[CodeCompletion] Guard for null interface type in calculateTypeRelationForDecl (#18591)
Fixes a crash. https://bugs.swift.org/browse/SR-8470 rdar://problem/43057054
1 parent a6fd082 commit 31f0f28

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ calculateTypeRelationForDecl(const Decl *D, Type ExpectedType,
961961
bool UseFuncResultType = true) {
962962
auto VD = dyn_cast<ValueDecl>(D);
963963
auto DC = D->getDeclContext();
964-
if (!VD)
964+
if (!VD || !VD->hasInterfaceType())
965965
return CodeCompletionResult::ExpectedTypeRelation::Unrelated;
966966

967967
if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {

test/IDE/complete_call_arg.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FORCED_IUO | %FileCheck %s -check-prefix=MEMBEROF_IUO
4747

4848
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENERIC_TO_GENERIC | %FileCheck %s -check-prefix=GENERIC_TO_GENERIC
49+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NESTED_CLOSURE | %FileCheck %s -check-prefix=NESTED_CLOSURE
4950

5051
var i1 = 1
5152
var i2 = 2
@@ -416,3 +417,11 @@ class Bar {
416417
// MEMBEROF_IUO: Decl[InstanceVar]/CurrNominal: x[#Int#]; name=x
417418
// MEMBEROF_IUO: End completions
418419
}
420+
421+
func curry<T1, T2, R>(_ f: @escaping (T1, T2) -> R) -> (T1) -> (T2) -> R {
422+
return { t1 in { t2 in f(#^NESTED_CLOSURE^#, t2) } }
423+
// NESTED_CLOSURE: Begin completions
424+
// FIXME: Should be '/TypeRelation[Invalid]: t2[#T2#]'
425+
// NESTED_CLOSURE: Decl[LocalVar]/Local: t2; name=t2
426+
// NESTED_CLOSURE: Decl[LocalVar]/Local: t1[#T1#]; name=t1
427+
}

0 commit comments

Comments
 (0)