Skip to content

[5.0][CodeCompletion] Analyze the parent of initializer #22732

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
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
6 changes: 5 additions & 1 deletion lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5409,7 +5409,11 @@ class CodeCompletionTypeContextAnalyzer {
// We cannot analyze without target.
if (!ParsedExpr)
return false;
DC->walkContext(Finder);

// For 'Initializer' context, we need to look into its parent because it
// might constrain the initializer's type.
auto analyzeDC = isa<Initializer>(DC) ? DC->getParent() : DC;
analyzeDC->walkContext(Finder);

for (auto It = Finder.Ancestors.rbegin(); It != Finder.Ancestors.rend();
++ It) {
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/complete_in_accessors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func returnsInt() -> Int {}

// WITH_MEMBER_DECLS_INIT: Begin completions
// WITH_MEMBER_DECLS_INIT-DAG: Decl[Struct]/CurrModule: FooStruct[#FooStruct#]{{; name=.+$}}
// WITH_MEMBER_DECLS_INIT-DAG: Decl[FreeFunction]/CurrModule: returnsInt()[#Int#]{{; name=.+$}}
// WITH_MEMBER_DECLS_INIT-DAG: Decl[FreeFunction]/CurrModule/TypeRelation[Identical]: returnsInt()[#Int#]{{; name=.+$}}
// WITH_MEMBER_DECLS_INIT-DAG: Decl[InstanceMethod]/CurrNominal: instanceFunc({#self: MemberAccessors#})[#(Int) -> Float#]{{; name=.+$}}
// WITH_MEMBER_DECLS_INIT: End completions

Expand Down
6 changes: 6 additions & 0 deletions test/IDE/complete_unresolved_members.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOADED_INIT_1 | %FileCheck %s -check-prefix=OVERLOADED_METHOD_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOADED_INIT_2 | %FileCheck %s -check-prefix=OVERLOADED_METHOD_1

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

enum SomeEnum1 {
case South
case North
Expand Down Expand Up @@ -535,3 +537,7 @@ func testOverload(val: HasOverloaded) {
let _ = HasOverloaded(e: .#^OVERLOADED_INIT_2^#)
// Same as OVERLOADED_METHOD_1.
}

struct TestingStruct {
var value: SomeEnum1 = .#^DECL_MEMBER_INIT_1^#
}