1
- // RUN: %target-typecheck-verify-swift -verify-ignore-unknown
1
+ // RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=off
2
+ // RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
2
3
3
4
protocol Fooable {
4
5
associatedtype Foo // expected-note{{protocol requires nested type 'Foo'; do you want to add it?}}
@@ -38,23 +39,31 @@ struct NestedConstraint<T> {
38
39
}
39
40
}
40
41
42
+ // CHECK-LABEL: same_types.(file).test2(_:u:)@
43
+ // CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == X, U.[Fooable]Foo == X>
41
44
func test2< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
42
45
where T. Foo == X , U. Foo == T . Foo {
43
46
return ( t. foo, u. foo)
44
47
}
45
48
49
+ // CHECK-LABEL: same_types.(file).test2a(_:u:)@
50
+ // CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == X, U.[Fooable]Foo == X>
46
51
func test2a< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
47
52
where T. Foo == X , T. Foo == U . Foo {
48
53
return ( t. foo, u. foo)
49
54
}
50
55
56
+ // CHECK-LABEL: same_types.(file).test3(_:u:)@
57
+ // CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == X, U.[Fooable]Foo == X>
51
58
func test3< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
52
59
where T. Foo == X , U. Foo == X , T. Foo == U . Foo {
53
60
// expected-warning@-1{{redundant same-type constraint 'U.Foo' == 'X'}}
54
61
// expected-note@-2{{same-type constraint 'T.Foo' == 'X' written here}}
55
62
return ( t. foo, u. foo)
56
63
}
57
64
65
+ // CHECK-LABEL: same_types.(file).fail1(_:u:)@
66
+ // CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == U.[Fooable]Foo>
58
67
func fail1<
59
68
T: Fooable , U: Fooable
60
69
> ( _ t: T , u: U ) -> ( X , Y )
@@ -63,6 +72,8 @@ func fail1<
63
72
return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type '(X, X)' to return type '(X, Y)'}}
64
73
}
65
74
75
+ // CHECK-LABEL: same_types.(file).fail2(_:u:)@
76
+ // CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == U.[Fooable]Foo>
66
77
func fail2<
67
78
T: Fooable , U: Fooable
68
79
> ( _ t: T , u: U ) -> ( X , Y )
@@ -75,6 +86,8 @@ func test4<T: Barrable>(_ t: T) -> Y where T.Bar == Y {
75
86
return t. bar
76
87
}
77
88
89
+ // CHECK-LABEL: same_types.(file).fail3@
90
+ // CHECK-NEXT: Generic signature: <T where T : Barrable>
78
91
func fail3< T: Barrable > ( _ t: T ) -> X
79
92
where T. Bar == X { // expected-error {{'X' does not conform to required protocol 'Fooable'}}
80
93
return t. bar // expected-error{{cannot convert return expression of type 'T.Bar' }}
@@ -88,25 +101,33 @@ func test6<T: Barrable>(_ t: T) -> (Y, X) where T.Bar == Y {
88
101
return ( t. bar, t. bar. foo)
89
102
}
90
103
104
+ // CHECK-LABEL: same_types.(file).test7@
105
+ // CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
91
106
func test7< T: Barrable > ( _ t: T ) -> ( Y , X ) where T. Bar == Y , T. Bar. Foo == X {
92
107
// expected-warning@-1{{neither type in same-type constraint ('Y.Foo' (aka 'X') or 'X') refers to a generic parameter or associated type}}
93
108
return ( t. bar, t. bar. foo)
94
109
}
95
110
111
+ // CHECK-LABEL: same_types.(file).fail4@
112
+ // CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
96
113
func fail4< T: Barrable > ( _ t: T ) -> ( Y , Z )
97
114
where
98
115
T. Bar == Y ,
99
116
T. Bar. Foo == Z { // expected-error{{generic signature requires types 'Y.Foo' (aka 'X') and 'Z' to be the same}}
100
117
return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type '(Y, X)' to return type '(Y, Z)'}}
101
118
}
102
119
120
+ // CHECK-LABEL: same_types.(file).fail5@
121
+ // CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
103
122
func fail5< T: Barrable > ( _ t: T ) -> ( Y , Z )
104
123
where
105
124
T. Bar. Foo == Z , // expected-note{{same-type constraint 'T.Bar.Foo' == 'Z' written here}}
106
125
T. Bar == Y { // expected-error{{'T.Bar.Foo' cannot be equal to both 'Y.Foo' (aka 'X') and 'Z'}}
107
126
return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type '(Y, X)' to return type '(Y, Z)'}}
108
127
}
109
128
129
+ // CHECK-LABEL: same_types.(file).test8@
130
+ // CHECK-NEXT: Generic signature: <T where T : Fooable>
110
131
func test8< T: Fooable > ( _ t: T )
111
132
where T. Foo == X , // expected-note{{same-type constraint 'T.Foo' == 'X' written here}}
112
133
T. Foo == Y { } // expected-error{{'T.Foo' cannot be equal to both 'Y' and 'X'}}
@@ -121,19 +142,25 @@ func fail6<T>(_ t: T) -> Int where T == Int { // expected-error{{same-type requi
121
142
return t
122
143
}
123
144
145
+ // CHECK-LABEL: same_types.(file).test8(_:u:)@
146
+ // CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
124
147
func test8< T: Barrable , U: Barrable > ( _ t: T , u: U ) -> ( Y , Y , X , X )
125
148
where T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
126
149
U. Bar. Foo == X , T. Bar == U . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
127
150
return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
128
151
}
129
152
153
+ // CHECK-LABEL: same_types.(file).test8a(_:u:)@
154
+ // CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
130
155
func test8a< T: Barrable , U: Barrable > ( _ t: T , u: U ) -> ( Y , Y , X , X )
131
156
where
132
157
T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
133
158
U. Bar. Foo == X , U. Bar == T . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
134
159
return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
135
160
}
136
161
162
+ // CHECK-LABEL: same_types.(file).test8b(_:u:)@
163
+ // CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
137
164
func test8b< T: Barrable , U: Barrable > ( _ t: T , u: U )
138
165
where U. Bar. Foo == X , // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
139
166
T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
@@ -166,6 +193,8 @@ struct Q : P {
166
193
}
167
194
168
195
struct S1 < T : P > {
196
+ // CHECK-LABEL: same_types.(file).S1.foo(x:y:)@
197
+ // CHECK-NEXT: Generic signature: <T, X, Y where T : P, X == T.[P]A, Y == T.[P]B>
169
198
func foo< X, Y> ( x: X , y: Y ) where X == T . A , Y == T . B {
170
199
print ( X . self)
171
200
print ( Y . self)
@@ -176,6 +205,8 @@ struct S1<T : P> {
176
205
S1 < Q > ( ) . foo ( x: 1 , y: 2 )
177
206
178
207
struct S2 < T : P > where T. A == T . B {
208
+ // CHECK-LABEL: same_types.(file).S2.foo(x:y:)@
209
+ // CHECK-NEXT: <T, X, Y where T : P, X == Y, Y == T.[P]A, T.[P]A == T.[P]B>
179
210
func foo< X, Y> ( x: X , y: Y ) where X == T . A , Y == T . B { // expected-error{{same-type requirement makes generic parameters 'X' and 'Y' equivalent}}
180
211
print ( X . self)
181
212
print ( Y . self)
@@ -186,6 +217,8 @@ struct S2<T : P> where T.A == T.B {
186
217
S2 < Q > ( ) . foo ( x: 1 , y: 2 )
187
218
188
219
struct S3 < T : P > {
220
+ // CHECK-LABEL: same_types.(file).S3.foo(x:y:)@
221
+ // CHECK-NEXT: <T, X, Y where T : P, X == Y, Y == T.[P]A>
189
222
func foo< X, Y> ( x: X , y: Y ) where X == T . A , Y == T . A { } // expected-error{{same-type requirement makes generic parameters 'X' and 'Y' equivalent}}
190
223
}
191
224
S3 < Q > ( ) . foo ( x: 1 , y: 2 )
@@ -208,6 +241,8 @@ struct QQ : P {
208
241
}
209
242
210
243
struct S4 < T : P > {
244
+ // CHECK-LABEL: same_types.(file).S4.foo(x:)@
245
+ // CHECK-NEXT: Generic signature: <T, X where T : P, X : PP, T.[P]A == X.[PP]A>
211
246
func foo< X : PP > ( x: X ) where X. A == T . A {
212
247
print ( x)
213
248
print ( X . self)
@@ -223,18 +258,24 @@ protocol P1 {
223
258
associatedtype Assoc
224
259
}
225
260
261
+ // CHECK-LABEL: same_types.(file).structuralSameType1@
262
+ // CHECK-NEXT: Generic signature: <A, B, T, U, V, W where A : P1, B : P1, T == V, U == W, A.[P1]Assoc == X1<T, U>, B.[P1]Assoc == X1<T, U>>
226
263
func structuralSameType1< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
227
264
where A. Assoc == X1 < T , U > , B. Assoc == X1 < V , W > , A. Assoc == B . Assoc { }
228
265
// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'V' equivalent}}
229
266
// expected-error@-2{{same-type requirement makes generic parameters 'U' and 'W' equivalent}}
230
267
231
268
typealias Tuple2 < T, U> = ( T , U )
232
269
270
+ // CHECK-LABEL: same_types.(file).structuralSameType2@
271
+ // CHECK-NEXT: Generic signature: <A, B, T, U, V, W where A : P1, B : P1, T == V, U == W, A.[P1]Assoc == (T, U), B.[P1]Assoc == (T, U)>
233
272
func structuralSameType2< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
234
273
where A. Assoc == Tuple2 < T , U > , B. Assoc == Tuple2 < V , W > , A. Assoc == B . Assoc { }
235
274
// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'V' equivalent}}
236
275
// expected-error@-2{{same-type requirement makes generic parameters 'U' and 'W' equivalent}}
237
276
277
+ // CHECK-LABEL: same_types.(file).structuralSameType3@
278
+ // CHECK-NEXT: Generic signature: <T, U, V, W where T == V, U == W>
238
279
func structuralSameType3< T, U, V, W> ( _: T , _: U , _: V , _: W )
239
280
where X1 < T , U > == X1 < V , W > { }
240
281
// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'V' equivalent}}
@@ -246,6 +287,8 @@ protocol P2 {
246
287
associatedtype Assoc2
247
288
}
248
289
290
+ // CHECK-LABEL: same_types.(file).structuralSameTypeRecursive1@
291
+ // CHECK-NEXT: Generic signature: <T, U>
249
292
func structuralSameTypeRecursive1< T: P2 , U> ( _: T , _: U )
250
293
where T. Assoc1 == Tuple2 < T . Assoc1 , U > // expected-error{{same-type constraint 'T.Assoc1' == '(T.Assoc1, U)' is recursive}}
251
294
{ }
@@ -257,6 +300,8 @@ protocol P4 {
257
300
associatedtype A
258
301
}
259
302
303
+ // CHECK-LABEL: same_types.(file).test9@
304
+ // CHECK-NEXT: Generic signature: <T where T : P4>
260
305
func test9< T> ( _: T ) where T. A == X , T: P4 , T. A: P3 { } // expected-error{{same-type constraint type 'X' does not conform to required protocol 'P3'}}
261
306
262
307
// Same-type constraint conflict through protocol where clauses.
@@ -273,6 +318,8 @@ struct X5a {}
273
318
274
319
struct X5b { }
275
320
321
+ // CHECK-LABEL: same_types.(file).test9(_:u:)@
322
+ // CHECK-NEXT: Generic signature: <T, U where T : P6, U : P6, T.[P6]Bar == U.[P6]Bar>
276
323
func test9< T: P6 , U: P6 > ( _ t: T , u: U )
277
324
where T. Bar. Foo1 == X5a , // expected-note{{same-type constraint 'T.Bar.Foo1' == 'X5a' written here}}
278
325
U. Bar. Foo2 == X5b , // expected-error{{'U.Bar.Foo2' cannot be equal to both 'X5b' and 'X5a'}}
@@ -282,36 +329,57 @@ func test9<T: P6, U: P6>(_ t: T, u: U)
282
329
// FIXME: Remove -verify-ignore-unknown.
283
330
// <unknown>:0: error: unexpected error produced: generic parameter τ_0_0.Bar.Foo cannot be equal to both 'Y.Foo' (aka 'X') and 'Z'
284
331
332
+ // CHECK-LABEL: same_types.(file).testMetatypeSameType@
333
+ // CHECK-NEXT: Generic signature: <T, U where T == U>
285
334
func testMetatypeSameType< T, U> ( _ t: T , _ u: U )
286
335
where T. Type == U . Type { }
287
336
// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'U' equivalent}}
288
337
// expected-warning@-2{{neither type in same-type constraint ('T.Type' or 'U.Type') refers to a generic parameter or associated type}}
289
338
339
+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity1@
340
+ // CHECK-NEXT: Generic signature: <U, T where U == T.Type>
290
341
func testSameTypeCommutativity1< U, T> ( _ t: T , _ u: U )
291
342
where T. Type == U { } // Equivalent to U == T.Type
292
343
// expected-error@-1{{same-type requirement makes generic parameter 'U' non-generic}}
293
344
345
+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity2@
346
+ // CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == U?>
294
347
func testSameTypeCommutativity2< U, T: P1 > ( _ t: T , _ u: U )
295
348
where U ? == T . Assoc { } // Ok, equivalent to T.Assoc == U?
296
349
350
+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity3@
351
+ // CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == (U) -> ()>
297
352
func testSameTypeCommutativity3< U, T: P1 > ( _ t: T , _ u: U )
298
353
where ( U ) -> ( ) == T . Assoc { } // Ok, equivalent to T.Assoc == (U) -> ()
299
354
355
+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity4@
356
+ // CHECK-NEXT: Generic signature: <U, T where T == (U) -> ()>
300
357
func testSameTypeCommutativity4< U, T> ( _ t: T , _ u: U )
301
358
where ( U ) -> ( ) == T { } // Equivalent to T == (U) -> ()
302
359
// expected-error@-1{{same-type requirement makes generic parameter 'T' non-generic}}
303
360
361
+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity5@
362
+ // CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == P3 & PPP>
304
363
func testSameTypeCommutativity5< U, T: P1 > ( _ t: T , _ u: U )
305
364
where PPP & P3 == T . Assoc { } // Ok, equivalent to T.Assoc == PPP & P3
306
365
366
+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity6@
367
+ // CHECK-NEXT: Generic signature: <U, T where T : P1>
307
368
func testSameTypeCommutativity6< U, T: P1 > ( _ t: T , _ u: U )
308
369
where U & P3 == T . Assoc { } // Equivalent to T.Assoc == U & P3
309
370
// expected-error@-1 {{non-protocol, non-class type 'U' cannot be used within a protocol-constrained type}}
310
371
311
- // rdar;//problem/46848889
372
+ // rdar://problem/46848889
373
+
374
+ // CHECK-LABEL: same_types.(file).Foo@
375
+ // CHECK-NEXT: Generic signature: <A, B, C where A : P1, B : P1, C : P1, A.[P1]Assoc == B.[P1]Assoc, B.[P1]Assoc == C.[P1]Assoc>
312
376
struct Foo < A: P1 , B: P1 , C: P1 > where A. Assoc == B . Assoc , A. Assoc == C . Assoc { }
313
377
378
+ // CHECK-LABEL: same_types.(file).Bar@
379
+ // CHECK-NEXT: Generic signature: <A, B where A : P1, B : P1, A.[P1]Assoc == B.[P1]Assoc>
314
380
struct Bar < A: P1 , B: P1 > where A. Assoc == B . Assoc {
381
+ // CHECK-LABEL: same_types.(file).Bar.f(with:)@
382
+ // CHECK-NEXT: Generic signature: <A, B, C where A : P1, B : P1, C : P1, A.[P1]Assoc == B.[P1]Assoc, B.[P1]Assoc == C.[P1]Assoc>
315
383
func f< C: P1 > ( with other: C ) -> Foo < A , B , C > where A. Assoc == C . Assoc {
316
384
// expected-note@-1 {{previous same-type constraint 'B.Assoc' == 'C.Assoc' inferred from type here}}
317
385
// expected-warning@-2 {{redundant same-type constraint 'A.Assoc' == 'C.Assoc'}}
0 commit comments