mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[codecomplete] Fix unresolved member completion for T within Optional<T>
We need to look through the optional and find the members of T when doing completion in Optional<T>. let x: Foo? = .foo We still don't correctly complete .some/.none, which requires reconciling the unbound generic type we get from the decl with the real bound generic type. rdar://44767478
This commit is contained in:
@@ -3752,10 +3752,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getUnresolvedMemberCompletions(ArrayRef<Type> Types) {
|
void getUnresolvedMemberCompletions(Type T) {
|
||||||
NeedLeadingDot = !HaveDot;
|
if (!T->getNominalOrBoundGenericNominal())
|
||||||
for (auto T : Types) {
|
return;
|
||||||
if (T && T->getNominalOrBoundGenericNominal()) {
|
|
||||||
// We can only say .foo where foo is a static member of the contextual
|
// We can only say .foo where foo is a static member of the contextual
|
||||||
// type and has the same type (or if the member is a function, then the
|
// type and has the same type (or if the member is a function, then the
|
||||||
// same result type) as the contextual type.
|
// same result type) as the contextual type.
|
||||||
@@ -3780,6 +3780,18 @@ public:
|
|||||||
TypeResolver.get(),
|
TypeResolver.get(),
|
||||||
/*includeInstanceMembers=*/false);
|
/*includeInstanceMembers=*/false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getUnresolvedMemberCompletions(ArrayRef<Type> Types) {
|
||||||
|
NeedLeadingDot = !HaveDot;
|
||||||
|
for (auto T : Types) {
|
||||||
|
if (T) {
|
||||||
|
// FIXME: we should also include .some/.none from optional itself but
|
||||||
|
// getUnresolvedMemberCompletions doesn't ever return them since the
|
||||||
|
// interface type in the FilteredDeclConsumer will not match the bound
|
||||||
|
// generic type expected.
|
||||||
|
T = T->lookThroughAllOptionalTypes();
|
||||||
|
getUnresolvedMemberCompletions(T);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_8 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_8 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
||||||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_9 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_9 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
||||||
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_OPT_1 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
||||||
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_OPT_2 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
||||||
|
|
||||||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_12 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_12 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
||||||
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_13 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=UNRESOLVED_13 | %FileCheck %s -check-prefix=UNRESOLVED_3
|
||||||
@@ -116,6 +118,7 @@ func OptionSetTaker6(_ Op1: SomeOptions2, _ Op2: SomeOptions1) {}
|
|||||||
func OptionSetTaker7(_ Op1: SomeOptions1, _ Op2: SomeOptions2) -> Int {return 0}
|
func OptionSetTaker7(_ Op1: SomeOptions1, _ Op2: SomeOptions2) -> Int {return 0}
|
||||||
|
|
||||||
func EnumTaker1(_ E : SomeEnum1) {}
|
func EnumTaker1(_ E : SomeEnum1) {}
|
||||||
|
func optionalEnumTaker1(_ : SomeEnum1?) {}
|
||||||
|
|
||||||
class OptionTakerContainer1 {
|
class OptionTakerContainer1 {
|
||||||
func OptionSetTaker1(_ op : SomeOptions1) {}
|
func OptionSetTaker1(_ op : SomeOptions1) {}
|
||||||
@@ -179,6 +182,12 @@ class C4 {
|
|||||||
func f3() {
|
func f3() {
|
||||||
OptionSetTaker5(.Option1, .Option4, .#^UNRESOLVED_12^#, .West)
|
OptionSetTaker5(.Option1, .Option4, .#^UNRESOLVED_12^#, .West)
|
||||||
}
|
}
|
||||||
|
func f4() {
|
||||||
|
var _: SomeEnum1? = .#^UNRESOLVED_OPT_1^#
|
||||||
|
}
|
||||||
|
func f5() {
|
||||||
|
optionalEnumTaker1(.#^UNRESOLVED_OPT_2^#)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// UNRESOLVED_3: Begin completions
|
// UNRESOLVED_3: Begin completions
|
||||||
// UNRESOLVED_3-DAG: Decl[EnumElement]/ExprSpecific: North[#SomeEnum1#]; name=North
|
// UNRESOLVED_3-DAG: Decl[EnumElement]/ExprSpecific: North[#SomeEnum1#]; name=North
|
||||||
|
|||||||
Reference in New Issue
Block a user