Skip to content

Commit 4a4ee3f

Browse files
committed
[CodeCompletion] Filter out inapplicable member from callee analysis
rdar://problem/48604807 / https://bugs.swift.org/browse/SR-9938
1 parent 3ee1add commit 4a4ee3f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ void collectPossibleCalleesByQualifiedLookup(
325325
if ((!isa<AbstractFunctionDecl>(VD) && !isa<SubscriptDecl>(VD)) ||
326326
VD->shouldHideFromEditor())
327327
continue;
328+
if (!isMemberDeclApplied(&DC, baseTy->getMetatypeInstanceType(), VD))
329+
continue;
328330
resolver->resolveDeclSignature(VD);
329331
if (!VD->hasInterfaceType())
330332
continue;

test/IDE/complete_constrained.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=MYSTRUCT_INT_DOT | %FileCheck %s -check-prefix=MYSTRUCT_INT_DOT
22
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=META_MYSTRUCT_INT_DOT | %FileCheck %s -check-prefix=META_MYSTRUCT_INT_DOT
3+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONDITIONAL_OVERLOAD_ARG | %FileCheck %s -check-prefix=CONDITIONAL_OVERLOAD_ARG
4+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONDITIONAL_OVERLOAD_INIT_ARG | %FileCheck %s -check-prefix=CONDITIONAL_OVERLOAD_ARG
5+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONDITIONAL_INAPPLICABLE_ARG | %FileCheck %s -check-prefix=CONDITIONAL_INAPPLICABLE_ARG
36

47
protocol SomeProto {
58
associatedtype Assoc
@@ -70,3 +73,44 @@ func foo(s: MyStruct<Int>) {
7073
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_None_AssocEqInt({#(self): MyStruct<Int>#})[#(U) -> Int#]; name=protoExt_None_AssocEqInt(self: MyStruct<Int>)
7174
// META_MYSTRUCT_INT_DOT: End completions
7275
}
76+
77+
//https://bugs.swift.org/browse/SR-9938
78+
enum Fruit { case apple }
79+
enum Vegetable { case broccoli }
80+
enum Meat { case chicken }
81+
82+
protocol EatsFruit { }
83+
protocol EatsVegetables { }
84+
protocol EatsMeat { }
85+
86+
struct Chef <Client> { }
87+
88+
extension Chef where Client: EatsFruit {
89+
init(_ favorite: Fruit) {}
90+
func cook(_ food: Fruit) { }
91+
}
92+
extension Chef where Client: EatsVegetables {
93+
init(_ favorite: Vegetable) {}
94+
func cook(_ food: Vegetable) { }
95+
}
96+
extension Chef where Client: EatsMeat {
97+
init(favorite: Meat) {}
98+
func cook(_ food: Meat) { }
99+
func eat(_ food: Meat) {}
100+
}
101+
102+
struct Vegetarian: EatsFruit, EatsVegetables { }
103+
104+
func testVegetarian(chef: Chef<Vegetarian>) {
105+
chef.cook(.#^CONDITIONAL_OVERLOAD_ARG^#)
106+
// CONDITIONAL_OVERLOAD_ARG: Begin completions, 2 items
107+
// CONDITIONAL_OVERLOAD_ARG-DAG: Decl[EnumElement]/ExprSpecific: apple[#Fruit#]; name=apple
108+
// CONDITIONAL_OVERLOAD_ARG-DAG: Decl[EnumElement]/ExprSpecific: broccoli[#Vegetable#]; name=broccoli
109+
// CONDITIONAL_OVERLOAD_ARG: End completions
110+
111+
var chefMeta: Chef<Vegetarian>.Type = Chef<Vegetarian>.self
112+
let _ = chefMeta.init(.#^CONDITIONAL_OVERLOAD_INIT_ARG^#)
113+
114+
chef.eat(.#^CONDITIONAL_INAPPLICABLE_ARG^#)
115+
// CONDITIONAL_INAPPLICABLE_ARG-NOT: Begin completion
116+
}

test/IDE/complete_value_expr.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT_INIT_2 | %FileCheck %s -check-prefix=PROTOCOL_EXT_INIT_2
151151
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT_INIT_3 | %FileCheck %s -check-prefix=PROTOCOL_EXT_INIT_3
152152
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT_INIT_4 | %FileCheck %s -check-prefix=PROTOCOL_EXT_INIT_4
153+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT_INIT_5 | %FileCheck %s -check-prefix=PROTOCOL_EXT_INIT_5
153154
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT_P4_DOT_1 | %FileCheck %s -check-prefix=PROTOCOL_EXT_P4_DOT
154155
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT_P4_DOT_2 | %FileCheck %s -check-prefix=PROTOCOL_EXT_P4_DOT
155156
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=PROTOCOL_EXT_P4_T_DOT_1 | %FileCheck %s -check-prefix=PROTOCOL_EXT_P4_T_DOT_1
@@ -1815,11 +1816,15 @@ func testProtExtInit2<S: P4 where S.T : P1>() {
18151816
S(#^PROTOCOL_EXT_INIT_2^#
18161817
S.#^PROTOCOL_EXT_INIT_3^#
18171818
S#^PROTOCOL_EXT_INIT_4^#
1819+
1820+
var sTy: S.Type = S.self
1821+
sTy.init(#^PROTOCOL_EXT_INIT_5^#
18181822
}
18191823
18201824
// PROTOCOL_EXT_INIT_2: Decl[Constructor]/CurrNominal: ['(']{#x: Int#}[')'][#P4#]{{; name=.+$}}
18211825
// PROTOCOL_EXT_INIT_3: Decl[Constructor]/CurrNominal: init({#x: Int#})[#P4#]{{; name=.+$}}
18221826
// PROTOCOL_EXT_INIT_4: Decl[Constructor]/CurrNominal: ({#x: Int#})[#P4#]{{; name=.+$}}
1827+
// PROTOCOL_EXT_INIT_5: Pattern/CurrModule: ['(']{#x: Int#}[')'][#S#]{{; name=.+$}}
18231828
18241829
extension P4 where Self.T == OnlyMe {
18251830
final func test1() {

0 commit comments

Comments
 (0)