Skip to content

Commit b17bfc1

Browse files
authored
Merge pull request #17588 from rintaro/ide-complete-rdar41227754
[CodeComplete] Typecheck SubscriptDecl context prior to completion
2 parents 747e318 + bccfd85 commit b17bfc1

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,8 +1371,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13711371
llvm_unreachable("module scope context handled above");
13721372

13731373
case DeclContextKind::SubscriptDecl:
1374-
// FIXME: what do we need to check here?
1375-
return true;
1374+
return typeCheckCompletionDecl(cast<SubscriptDecl>(DC));
13761375

13771376
case DeclContextKind::TopLevelCodeDecl:
13781377
return typeCheckTopLevelCodeDecl(cast<TopLevelCodeDecl>(DC));

test/IDE/complete_type_subscript.swift

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
protocol It {
2+
associatedtype Assoc
3+
}
4+
15
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PARAM_0 | %FileCheck %s -check-prefix=TOP_LEVEL_0
26
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_0 | %FileCheck %s -check-prefix=TOP_LEVEL_0
37

@@ -82,4 +86,35 @@ struct G5 {
8286
subscript<T>(x: T) -> T.#^GEN_RETURN_5^# { return 0 }
8387
}
8488
// GEN_PARAM_5: Keyword/None: Type[#T.Type#];
85-
// GEN_PARAM_5-NOT: Keyword/CurrNominal: self[#T#];
89+
// GEN_PARAM_5-NOT: Keyword/CurrNominal: self[#T#];
90+
91+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_PARAM_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
92+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_RETURN_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
93+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_EXT_PARAM_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
94+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_EXT_RETURN_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
95+
struct G6<T: It> {
96+
subscript(a x: T.#^GEN_PARAM_6^#) -> Int { return 0 }
97+
subscript(a x: Int) -> T.#^GEN_RETURN_6^# { return 0 }
98+
}
99+
extension G6 {
100+
subscript(b x: T.#^GEN_EXT_PARAM_6^#) -> Int { return 0 }
101+
subscript(b x: Int) -> T.#^GEN_EXT_RETURN_6^# { return 0 }
102+
}
103+
// GEN_PARAM_6-DAG: Decl[AssociatedType]/Super: Assoc;
104+
// GEN_PARAM_6-DAG: Keyword/None: Type[#T.Type#];
105+
106+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_PARAM_1 | %FileCheck %s -check-prefix=GENPROTO_1
107+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_RETURN_1 | %FileCheck %s -check-prefix=GENPROTO_1
108+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_EXT_PARAM_1 | %FileCheck %s -check-prefix=GENPROTO_1
109+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_EXT_RETURN_1 | %FileCheck %s -check-prefix=GENPROTO_1
110+
protocol GP1 {
111+
associatedtype I: It
112+
subscript(a x: I.#^GENPROTO_PARAM_1^#) -> Int
113+
subscript(ax: Int) -> I.#^GENPROTO_RETURN_1^#
114+
}
115+
extension GP1 {
116+
subscript(b x: I.#^GENPROTO_EXT_PARAM_1^#) -> Int { return 1 }
117+
subscript(b x: Int) -> I.#^GENPROTO_EXT_RETURN_1^# { return 1 }
118+
}
119+
// GENPROTO_1-DAG: Decl[AssociatedType]/Super: Assoc;
120+
// GENPROTO_1-DAG: Keyword/None: Type[#Self.I.Type#];

0 commit comments

Comments
 (0)