Skip to content

Commit fa8af3a

Browse files
committed
[CodeCompletion] Analyze the parent of initializer
For `Initializer` decl context, type context analyzer should look into its parent context because that might constrain initializer's type. rdar://problem/48208253 (swift-5.0-version of commit fd9b6a1)
1 parent 817dff3 commit fa8af3a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5409,7 +5409,11 @@ class CodeCompletionTypeContextAnalyzer {
54095409
// We cannot analyze without target.
54105410
if (!ParsedExpr)
54115411
return false;
5412-
DC->walkContext(Finder);
5412+
5413+
// For 'Initializer' context, we need to look into its parent because it
5414+
// might constrain the initializer's type.
5415+
auto analyzeDC = isa<Initializer>(DC) ? DC->getParent() : DC;
5416+
analyzeDC->walkContext(Finder);
54135417

54145418
for (auto It = Finder.Ancestors.rbegin(); It != Finder.Ancestors.rend();
54155419
++ It) {

test/IDE/complete_in_accessors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func returnsInt() -> Int {}
150150

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

test/IDE/complete_unresolved_members.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOADED_INIT_1 | %FileCheck %s -check-prefix=OVERLOADED_METHOD_1
7979
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=OVERLOADED_INIT_2 | %FileCheck %s -check-prefix=OVERLOADED_METHOD_1
8080

81+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DECL_MEMBER_INIT_1 | %FileCheck %s -check-prefix=UNRESOLVED_3
82+
8183
enum SomeEnum1 {
8284
case South
8385
case North
@@ -535,3 +537,7 @@ func testOverload(val: HasOverloaded) {
535537
let _ = HasOverloaded(e: .#^OVERLOADED_INIT_2^#)
536538
// Same as OVERLOADED_METHOD_1.
537539
}
540+
541+
struct TestingStruct {
542+
var value: SomeEnum1 = .#^DECL_MEMBER_INIT_1^#
543+
}

0 commit comments

Comments
 (0)