Skip to content

[CodeComplete] Typecheck SubscriptDecl context prior to completion #17588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
llvm_unreachable("module scope context handled above");

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

case DeclContextKind::TopLevelCodeDecl:
return typeCheckTopLevelCodeDecl(cast<TopLevelCodeDecl>(DC));
Expand Down
37 changes: 36 additions & 1 deletion test/IDE/complete_type_subscript.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
protocol It {
associatedtype Assoc
}

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PARAM_0 | %FileCheck %s -check-prefix=TOP_LEVEL_0
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=RETURN_0 | %FileCheck %s -check-prefix=TOP_LEVEL_0

Expand Down Expand Up @@ -82,4 +86,35 @@ struct G5 {
subscript<T>(x: T) -> T.#^GEN_RETURN_5^# { return 0 }
}
// GEN_PARAM_5: Keyword/None: Type[#T.Type#];
// GEN_PARAM_5-NOT: Keyword/CurrNominal: self[#T#];
// GEN_PARAM_5-NOT: Keyword/CurrNominal: self[#T#];

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_PARAM_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_RETURN_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_EXT_PARAM_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GEN_EXT_RETURN_6 | %FileCheck %s -check-prefix=GEN_PARAM_6
struct G6<T: It> {
subscript(a x: T.#^GEN_PARAM_6^#) -> Int { return 0 }
subscript(a x: Int) -> T.#^GEN_RETURN_6^# { return 0 }
}
extension G6 {
subscript(b x: T.#^GEN_EXT_PARAM_6^#) -> Int { return 0 }
subscript(b x: Int) -> T.#^GEN_EXT_RETURN_6^# { return 0 }
}
// GEN_PARAM_6-DAG: Decl[AssociatedType]/Super: Assoc;
// GEN_PARAM_6-DAG: Keyword/None: Type[#T.Type#];

// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_PARAM_1 | %FileCheck %s -check-prefix=GENPROTO_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_RETURN_1 | %FileCheck %s -check-prefix=GENPROTO_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_EXT_PARAM_1 | %FileCheck %s -check-prefix=GENPROTO_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=GENPROTO_EXT_RETURN_1 | %FileCheck %s -check-prefix=GENPROTO_1
protocol GP1 {
associatedtype I: It
subscript(a x: I.#^GENPROTO_PARAM_1^#) -> Int
subscript(ax: Int) -> I.#^GENPROTO_RETURN_1^#
}
extension GP1 {
subscript(b x: I.#^GENPROTO_EXT_PARAM_1^#) -> Int { return 1 }
subscript(b x: Int) -> I.#^GENPROTO_EXT_RETURN_1^# { return 1 }
}
// GENPROTO_1-DAG: Decl[AssociatedType]/Super: Assoc;
// GENPROTO_1-DAG: Keyword/None: Type[#Self.I.Type#];