Skip to content

Commit ae40265

Browse files
authored
Merge pull request swiftlang#77649 from hamishknight/tweak-complete-subscript-assert
2 parents dbf388c + f7e9222 commit ae40265

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
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: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=METATYPE_UNRESOLVED | %FileCheck %s -check-prefix=METATYPE_UNRESOLVED
2-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=METATYPE_UNRESOLVED_BRACKET | %FileCheck %s -check-prefix=METATYPE_UNRESOLVED_BRACKET
3-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=METATYPE_INT | %FileCheck %s -check-prefix=METATYPE_INT
4-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=METATYPE_INT_BRACKET | %FileCheck %s -check-prefix=METATYPE_INT_BRACKET
5-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INSTANCE_INT | %FileCheck %s -check-prefix=INSTANCE_INT
6-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INSTANCE_INT_BRACKET | %FileCheck %s -check-prefix=INSTANCE_INT_BRACKET
7-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=METATYPE_ARCHETYPE | %FileCheck %s -check-prefix=METATYPE_ARCHETYPE
8-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=METATYPE_ARCHETYPE_BRACKET | %FileCheck %s -check-prefix=METATYPE_ARCHETYPE_BRACKET
9-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INSTANCE_ARCHETYPE | %FileCheck %s -check-prefix=INSTANCE_ARCHETYPE
10-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INSTANCE_ARCHETYPE_BRACKET | %FileCheck %s -check-prefix=INSTANCE_ARCHETYPE_BRACKET
11-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=METATYPE_LABEL | %FileCheck %s -check-prefix=METATYPE_LABEL
12-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=INSTANCE_LABEL | %FileCheck %s -check-prefix=INSTANCE_LABEL
13-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SELF_IN_INSTANCEMETHOD | %FileCheck %s -check-prefix=SELF_IN_INSTANCEMETHOD
14-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SUPER_IN_INSTANCEMETHOD | %FileCheck %s -check-prefix=SUPER_IN_INSTANCEMETHOD
15-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SELF_IN_STATICMETHOD | %FileCheck %s -check-prefix=SELF_IN_STATICMETHOD
16-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SUPER_IN_STATICMETHOD | %FileCheck %s -check-prefix=SUPER_IN_STATICMETHOD
17-
18-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=LABELED_SUBSCRIPT | %FileCheck %s -check-prefix=LABELED_SUBSCRIPT
19-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TUPLE | %FileCheck %s -check-prefix=TUPLE
20-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=SETTABLE_SUBSCRIPT | %FileCheck %s -check-prefix=SETTABLE_SUBSCRIPT
1+
// RUN: %batch-code-completion
212

223
struct MyStruct<T> {
234
static subscript(x: Int, static defValue: T) -> MyStruct<T> {
@@ -152,3 +133,10 @@ func testSettableSub(x: inout HasSettableSub) {
152133
// SETTABLE_SUBSCRIPT-DAG: Pattern/CurrNominal/Flair[ArgLabels]: ['[']{#keyPath: KeyPath<HasSettableSub, Value>#}[']'][#Value#];
153134
// SETTABLE_SUBSCRIPT-DAG: Decl[Subscript]/CurrNominal/Flair[ArgLabels]: ['[']{#(a): String#}[']'][#@lvalue Int#];
154135
// 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)