forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplete_constrained.swift
152 lines (133 loc) · 8.13 KB
/
complete_constrained.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=MYSTRUCT_INT_DOT | %FileCheck %s -check-prefix=MYSTRUCT_INT_DOT
// 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
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONDITIONAL_OVERLOAD_ARG | %FileCheck %s -check-prefix=CONDITIONAL_OVERLOAD_ARG
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONDITIONAL_OVERLOAD_INIT_ARG | %FileCheck %s -check-prefix=CONDITIONAL_OVERLOAD_ARG
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONDITIONAL_INAPPLICABLE_ARG | %FileCheck %s -check-prefix=CONDITIONAL_INAPPLICABLE_ARG
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=CONDITIONAL_DEPENDENT_TYPEALIAS | %FileCheck %s -check-prefix=CONDITIONAL_DEPENDENT_TYPEALIAS
protocolSomeProto{
associatedtypeAssoc
}
extensionSomeProtowhere Assoc ==String{
func protoExt_AssocEqString_None()->Int{return1}
}
extensionSomeProtowhere Assoc ==Int{
func protoExt_AssocEqInt_None()->Int{return1}
}
extensionSomeProtowhere Assoc:SomeProto{
func protoExt_AssocConformsToSomeProto_None()->Int{return1}
}
extensionSomeProto{
func protoExt_None_AssocEqString<U>(_ x:U)->Intwhere Assoc ==String{return1}
func protoExt_None_AssocEqInt<U>(_ x:U)->Intwhere Assoc ==Int{return1}
func protoExt_None_AssocConformsToSomeProto<U>(_ x:U)->Intwhere Assoc:SomeProto{return1}
}
structMyStruct<T>:SomeProto{
typealiasAssoc=T
init<U>(int:U)where T ==Int{}
init<U>(str:U)where T ==String{}
init<U:SomeProto>(withConstrainedGenericParam:U){}
func methodWithConstrainedGenericParam<U:SomeProto>(x:U)->Int{return1}
}
extensionMyStructwhere T ==String{
func concreteExt_TEqString_None()->Int{return1}
}
extensionMyStructwhere T ==Int{
func concreteExt_TEqInt_None()->Int{return1}
}
extensionMyStructwhere T:SomeProto{
func concreteExt_TConformsToSomeProto_None()->Int{return1}
}
extensionMyStruct{
func concreteExt_None_TEqString<U>(_ x:U)->Intwhere T ==String{return1}
func concreteExt_None_TEqInt<U>(_ x:U)->Intwhere T ==Int{return1}
func concreteExt_None_TConformsToSomeProto<U>(_ x:U)->Intwhere T:SomeProto{return1}
}
protocolProto_Int{}
extensionProto_Int{
func conditional_Int()->Int{return1}
}
protocolProto_String{}
extensionProto_String{
func conditional_String()->Int{return1}
}
extensionMyStruct:Proto_Intwhere T ==Int{}
extensionMyStruct:Proto_Stringwhere T ==String{}
func foo(s:MyStruct<Int>){
let _ = s.#^MYSTRUCT_INT_DOT^#
// MYSTRUCT_INT_DOT: Begin completions, 7 items
// MYSTRUCT_INT_DOT-DAG: Keyword[self]/CurrNominal: self[#MyStruct<Int>#]; name=self
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: methodWithConstrainedGenericParam({#x: SomeProto#})[#Int#]; name=methodWithConstrainedGenericParam(x:)
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: concreteExt_TEqInt_None()[#Int#]; name=concreteExt_TEqInt_None()
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: concreteExt_None_TEqInt({#(x): U#})[#Int#]; name=concreteExt_None_TEqInt(:)
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_AssocEqInt_None()[#Int#]; name=protoExt_AssocEqInt_None()
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_None_AssocEqInt({#(x): U#})[#Int#]; name=protoExt_None_AssocEqInt(:)
// MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: conditional_Int()[#Int#]; name=conditional_Int()
let _ =MyStruct<Int>.#^META_MYSTRUCT_INT_DOT^#
// META_MYSTRUCT_INT_DOT: Begin completions, 11 items
// META_MYSTRUCT_INT_DOT-DAG: Keyword[self]/CurrNominal: self[#MyStruct<Int>.Type#]; name=self
// META_MYSTRUCT_INT_DOT-DAG: Keyword/CurrNominal: Type[#MyStruct<Int>.Type#]; name=Type
// META_MYSTRUCT_INT_DOT-DAG: Decl[TypeAlias]/CurrNominal: Assoc[#Int#]; name=Assoc
// META_MYSTRUCT_INT_DOT-DAG: Decl[Constructor]/CurrNominal: init({#int: U#})[#MyStruct<Int>#]; name=init(int:)
// META_MYSTRUCT_INT_DOT-DAG: Decl[Constructor]/CurrNominal: init({#withConstrainedGenericParam: SomeProto#})[#MyStruct<Int>#]; name=init(withConstrainedGenericParam:)
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: methodWithConstrainedGenericParam({#(self): MyStruct<Int>#})[#(x: SomeProto) -> Int#]; name=methodWithConstrainedGenericParam(:)
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: concreteExt_TEqInt_None({#(self): MyStruct<Int>#})[#() -> Int#]; name=concreteExt_TEqInt_None(:)
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/CurrNominal: concreteExt_None_TEqInt({#(self): MyStruct<Int>#})[#(U) -> Int#]; name=concreteExt_None_TEqInt(:)
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_AssocEqInt_None({#(self): MyStruct<Int>#})[#() -> Int#]; name=protoExt_AssocEqInt_None(:)
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: protoExt_None_AssocEqInt({#(self): MyStruct<Int>#})[#(U) -> Int#]; name=protoExt_None_AssocEqInt(:)
// META_MYSTRUCT_INT_DOT-DAG: Decl[InstanceMethod]/Super: conditional_Int({#(self): MyStruct<Int>#})[#() -> Int#]; name=conditional_Int(:)
}
// https://github.com/apple/swift/issues/52344
enumFruit{case apple }
enumVegetable{case broccoli }
enumMeat{case chicken }
protocolEatsFruit{}
protocolEatsVegetables{}
protocolEatsMeat{}
structChef<Client>{}
extensionChefwhere Client:EatsFruit{
init(_ favorite:Fruit){}
func cook(_ food:Fruit){}
}
extensionChefwhere Client:EatsVegetables{
init(_ favorite:Vegetable){}
func cook(_ food:Vegetable){}
}
extensionChefwhere Client:EatsMeat{
init(favorite:Meat){}
func cook(_ food:Meat){}
func eat(_ food:Meat){}
}
structVegetarian:EatsFruit,EatsVegetables{}
func testVegetarian(chef:Chef<Vegetarian>){
chef.cook(.#^CONDITIONAL_OVERLOAD_ARG^#)
// CONDITIONAL_OVERLOAD_ARG: Begin completions, 4 items
// CONDITIONAL_OVERLOAD_ARG-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: apple[#Fruit#]; name=apple
// CONDITIONAL_OVERLOAD_ARG-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): Fruit#})[#(into: inout Hasher) -> Void#]; name=hash(:)
// CONDITIONAL_OVERLOAD_ARG-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: broccoli[#Vegetable#]; name=broccoli
// CONDITIONAL_OVERLOAD_ARG-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): Vegetable#})[#(into: inout Hasher) -> Void#]; name=hash(:)
varchefMeta:Chef<Vegetarian>.Type= Chef<Vegetarian>.self
let _ = chefMeta.init(.#^CONDITIONAL_OVERLOAD_INIT_ARG^#)
chef.eat(.#^CONDITIONAL_INAPPLICABLE_ARG^#)
// Note: 'eat' is from an inapplicable constrained extension. We complete as if the user intends to address that later
// (e.g. by adding the missing 'Meat' conformance to 'Vegetarian' - clearly not the intention here - but replace 'Meat' with 'Equatable').
// CONDITIONAL_INAPPLICABLE_ARG: Begin completions, 2 items
// CONDITIONAL_INAPPLICABLE_ARG-DAG: Decl[EnumElement]/CurrNominal/Flair[ExprSpecific]/TypeRelation[Convertible]: chicken[#Meat#]; name=chicken
// CONDITIONAL_INAPPLICABLE_ARG-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Invalid]: hash({#(self): Meat#})[#(into: inout Hasher) -> Void#]; name=hash(:)
}
// rdar://problem/53401609
protocolMyProto{
associatedtypeIndex
}
extensionMyProtowhere Index:Strideable, Index.Stride ==Int{
func indices(){}
}
structMyConcrete{}
extensionMyConcrete:MyProto{
typealiasIndex=Int
}
func testHasIndex(value:MyConcrete){
value.#^CONDITIONAL_DEPENDENT_TYPEALIAS^#
// CONDITIONAL_DEPENDENT_TYPEALIAS: Begin completions, 2 items
// CONDITIONAL_DEPENDENT_TYPEALIAS-DAG: Keyword[self]/CurrNominal: self[#MyConcrete#];
// CONDITIONAL_DEPENDENT_TYPEALIAS-DAG: Decl[InstanceMethod]/Super: indices()[#Void#];
}