Skip to content

Commit c2e1567

Browse files
authored
Merge pull request #17594 from rintaro/4.2-ide-complete-rdar41227754
[4.2][CodeComplete] Typecheck SubscriptDecl context prior to completion
2 parents 6079032 + 6e35ceb commit c2e1567

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
@@ -1370,8 +1370,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13701370
llvm_unreachable("module scope context handled above");
13711371

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

13761375
case DeclContextKind::TopLevelCodeDecl:
13771376
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

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

0 commit comments

Comments
 (0)