Skip to content

Commit c386124

Browse files
committed
Test: additional test coverage for SuppressedAssociatedTypesWithDefaults
1 parent ab1d83a commit c386124

File tree

2 files changed

+163
-0
lines changed

2 files changed

+163
-0
lines changed

test/Generics/inverse_assoc_types.swift

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,115 @@ protocol Iterable<Element>: ~Copyable {
5050
associatedtype Element: ~Copyable
5151
}
5252

53+
54+
struct ReqC<T: Copyable> {}
55+
56+
func reqC<T: Copyable>(_ t: T) {} // expected-note 8{{'where T: Copyable' is implicit here}}
57+
58+
59+
protocol ProvideA<A>: ~Copyable {
60+
associatedtype A: ~Copyable, ProvideB
61+
}
62+
63+
protocol ProvideB: ~Copyable {
64+
associatedtype B: ~Copyable, ProvideA
65+
}
66+
67+
// via bound-parameter requirement inference, all of these associated types become copyable
68+
func inferenceRec<T: ProvideA>(_ t: T,
69+
_ a1: ReqC<T.A>,
70+
_ b2: ReqC<T.A.B>,
71+
_ a3: ReqC<T.A.B.A>,
72+
_ b4: ReqC<T.A.B.A.B>,
73+
_ a5: ReqC<T.A.B.A.B.A>,
74+
_ b6: ReqC<T.A.B.A.B.A.B>,
75+
_ a7: ReqC<T.A.B.A.B.A.B.A>,
76+
_ b8: ReqC<T.A.B.A.B.A.B.A.B>,
77+
_ a9: ReqC<T.A.B.A.B.A.B.A.B.A>,
78+
_ b10: ReqC<T.A.B.A.B.A.B.A.B.A.B>,
79+
_ a11: ReqC<T.A.B.A.B.A.B.A.B.A.B.A>,
80+
_ b12: ReqC<T.A.B.A.B.A.B.A.B.A.B.A.B>
81+
) {}
82+
83+
// Otherwise, the archetypes infer Copyable based on the defaulting rule,
84+
// no matter the depth.
85+
func inferenceRec<T: ProvideA>(_ t: T,
86+
_ a1: borrowing T.A,
87+
_ b2: borrowing T.A.B,
88+
_ a3: borrowing T.A.B.A,
89+
_ b4: borrowing T.A.B.A.B,
90+
_ a5: borrowing T.A.B.A.B.A,
91+
_ b6: borrowing T.A.B.A.B.A.B,
92+
_ a7: borrowing T.A.B.A.B.A.B.A,
93+
_ b8: borrowing T.A.B.A.B.A.B.A.B,
94+
_ a9: borrowing T.A.B.A.B.A.B.A.B.A,
95+
_ b10: borrowing T.A.B.A.B.A.B.A.B.A.B,
96+
_ a11: borrowing T.A.B.A.B.A.B.A.B.A.B.A,
97+
_ b12: borrowing T.A.B.A.B.A.B.A.B.A.B.A.B
98+
) {
99+
reqC(a1)
100+
reqC(b2) // expected-error {{requires that 'T.A.B' conform to 'Copyable'}}
101+
reqC(a3)
102+
reqC(b4) // expected-error {{requires that 'T.A.B.A.B' conform to 'Copyable'}}
103+
reqC(a5)
104+
reqC(b6) // expected-error {{requires that 'T.A.B.A.B.A.B' conform to 'Copyable'}}
105+
reqC(a7)
106+
reqC(b8) // expected-error {{requires that 'T.A.B.A.B.A.B.A.B' conform to 'Copyable'}}
107+
reqC(a9)
108+
reqC(b10) // expected-error {{requires that 'T.A.B.A.B.A.B.A.B.A.B' conform to 'Copyable'}}
109+
reqC(a11)
110+
reqC(b12) // expected-error {{requires that 'T.A.B.A.B.A.B.A.B.A.B.A.B' conform to 'Copyable'}}
111+
}
112+
113+
protocol Gen<E>: ~Copyable {
114+
associatedtype E: ~Copyable, Gen
115+
associatedtype I: ~Copyable, Gen
116+
117+
func e() -> E
118+
func i() -> I
119+
}
120+
121+
func checkExistential(_ s: any Gen) {
122+
reqC(s.e())
123+
reqC(s.e().e())
124+
reqC(s.e().e().e())
125+
reqC(s.e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e().e())
126+
127+
reqC(s.i()) // expected-error {{requires that 'T' conform to 'Copyable'}}
128+
reqC(s.i().e())
129+
reqC(s.i().e().i()) // expected-error {{requires that 'T' conform to 'Copyable'}}
130+
reqC(s.i().e().i().e())
131+
}
132+
133+
protocol Veggie<A> {
134+
associatedtype A: ~Copyable
135+
associatedtype NeedsCopyable
136+
}
137+
protocol Carrot: Veggie
138+
where Self.NeedsCopyable: ~Copyable {} // expected-error {{'Self.NeedsCopyable' required to be 'Copyable' but is marked with '~Copyable'}}
139+
// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.NeedsCopyable' defined in outer scope}}
140+
141+
protocol CarrotCake: Carrot where Self.A: ~Copyable {} // expected-error {{'Self.A' required to be 'Copyable' but is marked with '~Copyable'}}
142+
// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.A' defined in outer scope}}
143+
144+
145+
protocol Bird {
146+
associatedtype Song
147+
}
148+
149+
protocol Eagle: Bird where Self.Song: ~Copyable {}// expected-error {{'Self.Song' required to be 'Copyable' but is marked with '~Copyable'}}
150+
// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.Song' defined in outer scope}}
151+
152+
153+
protocol Pushable<Element> {
154+
associatedtype Element: ~Copyable
155+
}
156+
157+
struct Stack<Scope: Pushable> {}
158+
159+
func push<Val>(_ s: Stack<Val>, _ v: Val)
160+
where Val.Element: ~Copyable {} // expected-error {{'Val.Element' required to be 'Copyable' but is marked with '~Copyable'}}
161+
162+
protocol Stackable<Element>: Pushable {}
163+
164+
extension Stackable where Element: ~Copyable {} // expected-error {{'Self.Element' required to be 'Copyable' but is marked with '~Copyable'}}

test/Generics/inverse_signatures_assoc_types.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ extension Pri_IIII {}
7979
func test2<X, Y, Z>(_ x: X, y: Y, z: Z) where
8080
X: Pri_CI, Y: Pri_II, Z: Pri_IIII {}
8181

82+
struct RequireCopy<X: Copyable> {}
83+
84+
// CHECK-LABEL: .ImplyP@
85+
// CHECK-NEXT: Generic signature: <V where V : Pri_CI, V.[Pri_CI]A : Copyable>
86+
struct ImplyP<V> where V: Pri_CI {}
87+
88+
// CHECK-LABEL: .implied1@
89+
// CHECK-NEXT: Generic signature: <T where T : Pri_CI, T.[Pri_CI]A : Copyable>
90+
func implied1<T>(_ t: ImplyP<T>) {}
91+
8292
// CHECK-LABEL: .P3@
8393
// CHECK: Requirement signature: <Self where Self.[P3]B : Copyable>
8494
protocol P3 where Self: (~Copyable & ~Escapable) { associatedtype B: ~Escapable }
@@ -181,6 +191,28 @@ protocol Derived3<Elm>: Base where Elm: ~Copyable {}
181191
// CHECK-NEXT: Requirement signature: <Self where Self : Base>
182192
protocol Derived4<Elm>: Base, ~Copyable where Elm: ~Copyable {}
183193

194+
// CHECK-LABEL: .Derived5@
195+
// CHECK-NEXT: Requirement signature: <Self where Self : Copyable, Self : Base, Self.[Base]Elm : Copyable>
196+
protocol Derived5: Base {}
197+
198+
// CHECK-LABEL: .Derived6@
199+
// CHECK-NEXT: Requirement signature: <Self where Self : Copyable, Self : Base, Self.[Base]Elm : Copyable>
200+
protocol Derived6<Iter>: Base {}
201+
202+
// CHECK-LABEL: .SecondOrder@
203+
// CHECK-NEXT: Requirement signature: <Self where Self : Derived6, Self.[Base]Iter : Copyable>
204+
protocol SecondOrder: Derived6 {}
205+
206+
// CHECK-LABEL: .SecondOrderSupp1@
207+
// CHECK-NEXT: Requirement signature: <Self where Self : Derived6>
208+
protocol SecondOrderSupp1: Derived6 where Self.Iter: ~Copyable {}
209+
210+
// CHECK-LABEL: .Derived7@
211+
// CHECK-NEXT: Requirement signature: <Self where Self : Copyable, Self : Base, Self.[Base]Elm : Copyable, Self.[Base]Iter : Copyable>
212+
protocol Derived7: Base {
213+
associatedtype Iter
214+
}
215+
184216

185217
// CHECK-LABEL: .SameType@
186218
// CHECK-NEXT: Requirement signature: <Self where Self : Copyable, Self : Escapable,
@@ -231,3 +263,22 @@ func testExpansion1<T>(_ t: T, _ a: T.A, _ aa: T.A.A, _ aaa: T.A.A.A)
231263
func testExpansion2<T>(_ t: borrowing T) where
232264
T: ~Copyable & Ping, T.A: ~Copyable & Ping, T.A.A: ~Copyable & Ping,
233265
T.B: Ping, T.B.B: Ping {}
266+
267+
268+
// CHECK-LABEL: .Iterable@
269+
// CHECK-NEXT: Requirement signature: <Self where Self : Escapable, Self.[Iterable]Element : Escapable>
270+
protocol Iterable<Element>: ~Copyable {
271+
associatedtype Element: ~Copyable
272+
}
273+
274+
// CHECK-LABEL: .PersistedDictionary@
275+
// CHECK-NEXT: Requirement signature: <Self where Self : Iterable, Self.[Iterable]Element == Self.[PersistedDictionary]Value, Self.[PersistedDictionary]Key : Escapable, Self.[PersistedDictionary]Strategy : Escapable>
276+
protocol PersistedDictionary<Key, Value>: ~Copyable, Iterable<Self.Value> {
277+
associatedtype Key: ~Copyable
278+
associatedtype Value: ~Copyable
279+
associatedtype Strategy: ~Copyable
280+
}
281+
282+
// CHECK-LABEL: ExtensionDecl line={{.*}} base=PersistedDictionary
283+
// CHECK-NEXT: Generic signature: <Self where Self : Copyable, Self : PersistedDictionary, Self.[Iterable]Element : Copyable, Self.[PersistedDictionary]Key : Copyable>
284+
extension PersistedDictionary {}

0 commit comments

Comments
 (0)