Skip to content

Commit f7e9222

Browse files
committed
[Completion] Tweak assert for subscript call pattern
We may not have a semantic context kind if the subscript decl is missing, for cases such as the implicit `keyPath` subscript. rdar://139333904
1 parent b81d0e7 commit f7e9222

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/IDE/ArgumentCompletion.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,15 @@ void ArgumentTypeCheckCompletionCallback::collectResults(
374374
}
375375
if (Result.FuncTy) {
376376
if (auto FuncTy = Result.FuncTy) {
377+
// Only show call pattern completions if the function isn't
378+
// overridden.
377379
if (ShadowedDecls.count(Result.FuncD) == 0) {
378-
// Don't show call pattern completions if the function is
379-
// overridden.
380380
if (Result.IsSubscript) {
381-
assert(SemanticContext != SemanticContextKind::None);
381+
// The subscript decl may not be preset for e.g the implicit
382+
// `keyPath:` subscript. Such a subscript is allowed on any
383+
// non-nominal type, so the semantic context may be none.
382384
auto *SD = dyn_cast_or_null<SubscriptDecl>(Result.FuncD);
385+
assert(!SD || SemanticContext != SemanticContextKind::None);
383386
Lookup.addSubscriptCallPattern(FuncTy, SD, SemanticContext);
384387
} else {
385388
auto *FD = dyn_cast_or_null<AbstractFunctionDecl>(Result.FuncD);

test/IDE/complete_subscript.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,10 @@ func testSettableSub(x: inout HasSettableSub) {
133133
// SETTABLE_SUBSCRIPT-DAG: Pattern/CurrNominal/Flair[ArgLabels]: ['[']{#keyPath: KeyPath<HasSettableSub, Value>#}[']'][#Value#];
134134
// SETTABLE_SUBSCRIPT-DAG: Decl[Subscript]/CurrNominal/Flair[ArgLabels]: ['[']{#(a): String#}[']'][#@lvalue Int#];
135135
// SETTABLE_SUBSCRIPT-DAG: Decl[LocalVar]/Local/TypeRelation[Convertible]: local[#String#]; name=local
136+
137+
// rdar://139333904 - Make sure we don't hit an assertion.
138+
func testFnKeyPathSubscript() {
139+
// The keyPath: subscript is supported on all non-nominal types, including functions.
140+
test1[#^FN_KEYPATH_SUBSCRIPT^#]
141+
// FN_KEYPATH_SUBSCRIPT: Pattern/None/Flair[ArgLabels]: ['[']{#keyPath: KeyPath<() -> (), Value>#}[']'][#Value#]; name=keyPath:
142+
}

0 commit comments

Comments
 (0)