1
- // RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=off
1
+ // RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=on
2
2
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
3
3
4
4
protocol Fooable {
@@ -57,29 +57,26 @@ func test2a<T: Fooable, U: Fooable>(_ t: T, u: U) -> (X, X)
57
57
// CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == X, U.[Fooable]Foo == X>
58
58
func test3< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
59
59
where T. Foo == X , U. Foo == X , T. Foo == U . Foo {
60
- // expected-warning@-1{{redundant same-type constraint 'U.Foo' == 'X'}}
61
- // expected-note@-2{{same-type constraint 'T.Foo' == 'X' written here}}
60
+ // expected-warning@-1{{redundant same-type constraint 'T.Foo' == 'X'}}
62
61
return ( t. foo, u. foo)
63
62
}
64
63
65
64
// CHECK-LABEL: same_types.(file).fail1(_:u:)@
66
65
// CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == U.[Fooable]Foo>
67
- func fail1<
66
+ func fail1< // expected-error{{no type for 'T.Foo' can satisfy both 'T.Foo == X' and 'T.Foo == Y'}}
68
67
T: Fooable , U: Fooable
69
68
> ( _ t: T , u: U ) -> ( X , Y )
70
- where T. Foo == X , U. Foo == Y , T. Foo == U . Foo { // expected-error{{'U.Foo' cannot be equal to both 'Y' and 'X'}}
71
- // expected-note@-1{{same-type constraint 'T.Foo' == 'X' written here}}
72
- return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type '(X, X)' to return type '(X, Y)'}}
69
+ where T. Foo == X , U. Foo == Y , T. Foo == U . Foo {
70
+ return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type '(T.Foo, T.Foo)' to return type '(X, Y)'}}
73
71
}
74
72
75
73
// CHECK-LABEL: same_types.(file).fail2(_:u:)@
76
74
// CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == U.[Fooable]Foo>
77
- func fail2<
75
+ func fail2< // expected-error{{no type for 'T.Foo' can satisfy both 'T.Foo == Y' and 'T.Foo == X'}}
78
76
T: Fooable , U: Fooable
79
77
> ( _ t: T , u: U ) -> ( X , Y )
80
- where T. Foo == U . Foo , T. Foo == X , U. Foo == Y { // expected-error{{'U.Foo' cannot be equal to both 'Y' and 'X'}}
81
- // expected-note@-1{{same-type constraint 'T.Foo' == 'X' written here}}
82
- return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type '(X, X)' to return type '(X, Y)'}}
78
+ where T. Foo == U . Foo , T. Foo == X , U. Foo == Y {
79
+ return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type '(T.Foo, T.Foo)' to return type '(X, Y)'}}
83
80
}
84
81
85
82
func test4< T: Barrable > ( _ t: T ) -> Y where T. Bar == Y {
@@ -88,8 +85,8 @@ func test4<T: Barrable>(_ t: T) -> Y where T.Bar == Y {
88
85
89
86
// CHECK-LABEL: same_types.(file).fail3@
90
87
// CHECK-NEXT: Generic signature: <T where T : Barrable>
91
- func fail3< T: Barrable > ( _ t: T ) -> X
92
- where T. Bar == X { // expected-error {{'X' does not conform to required protocol 'Fooable'}}
88
+ func fail3< T: Barrable > ( _ t: T ) -> X // expected-error {{no type for 'T.Bar' can satisfy both 'T.Bar == X' and 'T.Bar : Fooable'}}
89
+ where T. Bar == X {
93
90
return t. bar // expected-error{{cannot convert return expression of type 'T.Bar' }}
94
91
}
95
92
@@ -104,7 +101,7 @@ func test6<T: Barrable>(_ t: T) -> (Y, X) where T.Bar == Y {
104
101
// CHECK-LABEL: same_types.(file).test7@
105
102
// CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
106
103
func test7< T: Barrable > ( _ t: T ) -> ( Y , X ) where T. Bar == Y , T. Bar. Foo == X {
107
- // expected-warning@-1{{neither type in same-type constraint ( 'Y.Foo' (aka 'X') or 'X') refers to a generic parameter or associated type }}
104
+ // expected-warning@-1{{redundant same-type constraint 'Y.Foo' (aka 'X') == 'X'}}
108
105
return ( t. bar, t. bar. foo)
109
106
}
110
107
@@ -121,31 +118,31 @@ func fail4<T: Barrable>(_ t: T) -> (Y, Z)
121
118
// CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
122
119
func fail5< T: Barrable > ( _ t: T ) -> ( Y , Z )
123
120
where
124
- T. Bar. Foo == Z , // expected-note{{same-type constraint 'T.Bar. Foo' == ' Z' written here }}
125
- T. Bar == Y { // expected-error{{'T.Bar.Foo' cannot be equal to both 'Y.Foo' (aka 'X') and 'Z'}}
121
+ T. Bar. Foo == Z , // expected-error{{generic signature requires types 'Y. Foo' (aka 'X') and ' Z' to be the same }}
122
+ T. Bar == Y {
126
123
return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type '(Y, X)' to return type '(Y, Z)'}}
127
124
}
128
125
129
126
// CHECK-LABEL: same_types.(file).test8@
130
127
// CHECK-NEXT: Generic signature: <T where T : Fooable>
131
- func test8< T: Fooable > ( _ t: T )
132
- where T. Foo == X , // expected-note{{same-type constraint 'T.Foo' == 'X' written here}}
133
- T. Foo == Y { } // expected-error{{'T.Foo' cannot be equal to both 'Y' and 'X'}}
128
+ func test8< T: Fooable > ( _ t: T ) // expected-error{{no type for 'T.Foo' can satisfy both 'T.Foo == Y' and 'T.Foo == X'}}
129
+ where T. Foo == X ,
130
+ T. Foo == Y { }
134
131
135
132
136
133
func testAssocTypeEquivalence< T: Fooable > ( _ fooable: T ) -> X . Type
137
134
where T. Foo == X {
138
135
return T . Foo. self
139
136
}
140
137
141
- func fail6< T> ( _ t: T ) -> Int where T == Int { // expected-error {{same-type requirement makes generic parameter 'T' non-generic}}
138
+ func fail6< T> ( _ t: T ) -> Int where T == Int { // expected-warning {{same-type requirement makes generic parameter 'T' non-generic}}
142
139
return t
143
140
}
144
141
145
142
// CHECK-LABEL: same_types.(file).test8(_:u:)@
146
143
// CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
147
144
func test8< T: Barrable , U: Barrable > ( _ t: T , u: U ) -> ( Y , Y , X , X )
148
- where T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
145
+ where T. Bar == Y ,
149
146
U. Bar. Foo == X , T. Bar == U . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
150
147
return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
151
148
}
@@ -154,7 +151,7 @@ func test8<T: Barrable, U: Barrable>(_ t: T, u: U) -> (Y, Y, X, X)
154
151
// CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
155
152
func test8a< T: Barrable , U: Barrable > ( _ t: T , u: U ) -> ( Y , Y , X , X )
156
153
where
157
- T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
154
+ T. Bar == Y ,
158
155
U. Bar. Foo == X , U. Bar == T . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
159
156
return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
160
157
}
@@ -163,7 +160,7 @@ func test8a<T: Barrable, U: Barrable>(_ t: T, u: U) -> (Y, Y, X, X)
163
160
// CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
164
161
func test8b< T: Barrable , U: Barrable > ( _ t: T , u: U )
165
162
where U. Bar. Foo == X , // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
166
- T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
163
+ T. Bar == Y ,
167
164
T. Bar == U . Bar {
168
165
}
169
166
@@ -207,7 +204,8 @@ S1<Q>().foo(x: 1, y: 2)
207
204
struct S2 < T : P > where T. A == T . B {
208
205
// CHECK-LABEL: same_types.(file).S2.foo(x:y:)@
209
206
// CHECK-NEXT: <T, X, Y where T : P, X == Y, Y == T.[P]A, T.[P]A == T.[P]B>
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}}
207
+ func foo< X, Y> ( x: X , y: Y ) where X == T . A , Y == T . B { // expected-warning{{same-type requirement makes generic parameters 'Y' and 'X' equivalent}}
208
+ // expected-warning@-1 {{redundant same-type constraint 'X' == 'T.A'}}
211
209
print ( X . self)
212
210
print ( Y . self)
213
211
print ( x)
@@ -219,7 +217,7 @@ S2<Q>().foo(x: 1, y: 2)
219
217
struct S3 < T : P > {
220
218
// CHECK-LABEL: same_types.(file).S3.foo(x:y:)@
221
219
// CHECK-NEXT: <T, X, Y where T : P, X == Y, Y == T.[P]A>
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}}
220
+ func foo< X, Y> ( x: X , y: Y ) where X == T . A , Y == T . A { } // expected-warning {{same-type requirement makes generic parameters 'Y ' and 'X ' equivalent}}
223
221
}
224
222
S3 < Q > ( ) . foo ( x: 1 , y: 2 )
225
223
@@ -262,25 +260,25 @@ protocol P1 {
262
260
// 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>>
263
261
func structuralSameType1< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
264
262
where A. Assoc == X1 < T , U > , B. Assoc == X1 < V , W > , A. Assoc == B . Assoc { }
265
- // expected-error@-1 {{same-type requirement makes generic parameters 'T ' and 'V ' equivalent}}
266
- // expected-error@-2 {{same-type requirement makes generic parameters 'U ' and 'W ' equivalent}}
263
+ // expected-warning@-2 {{same-type requirement makes generic parameters 'V ' and 'T ' equivalent}}
264
+ // expected-warning@-3 {{same-type requirement makes generic parameters 'W ' and 'U ' equivalent}}
267
265
268
266
typealias Tuple2 < T, U> = ( T , U )
269
267
270
268
// CHECK-LABEL: same_types.(file).structuralSameType2@
271
269
// 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)>
272
270
func structuralSameType2< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
273
271
where A. Assoc == Tuple2 < T , U > , B. Assoc == Tuple2 < V , W > , A. Assoc == B . Assoc { }
274
- // expected-error@-1 {{same-type requirement makes generic parameters 'T ' and 'V ' equivalent}}
275
- // expected-error@-2 {{same-type requirement makes generic parameters 'U ' and 'W ' equivalent}}
272
+ // expected-warning@-2 {{same-type requirement makes generic parameters 'V ' and 'T ' equivalent}}
273
+ // expected-warning@-3 {{same-type requirement makes generic parameters 'W ' and 'U ' equivalent}}
276
274
277
275
// CHECK-LABEL: same_types.(file).structuralSameType3@
278
276
// CHECK-NEXT: Generic signature: <T, U, V, W where T == V, U == W>
279
277
func structuralSameType3< T, U, V, W> ( _: T , _: U , _: V , _: W )
280
278
where X1 < T , U > == X1 < V , W > { }
281
- // expected-error@-1 {{same-type requirement makes generic parameters 'T ' and 'V ' equivalent}}
282
- // expected-error@-2 {{same-type requirement makes generic parameters 'U ' and 'W ' equivalent}}
283
- // expected-warning@-3{{neither type in same-type constraint ( 'X1<T, U>' or 'X1<V, W>') refers to a generic parameter or associated type }}
279
+ // expected-warning@-2 {{same-type requirement makes generic parameters 'V ' and 'T ' equivalent}}
280
+ // expected-warning@-3 {{same-type requirement makes generic parameters 'W ' and 'U ' equivalent}}
281
+ // expected-warning@-3{{redundant same-type constraint 'X1<T, U>' == 'X1<V, W>'}}
284
282
285
283
protocol P2 {
286
284
associatedtype Assoc1
@@ -289,8 +287,13 @@ protocol P2 {
289
287
290
288
// CHECK-LABEL: same_types.(file).structuralSameTypeRecursive1@
291
289
// CHECK-NEXT: Generic signature: <T, U>
290
+
291
+ // expected-error@+2 {{cannot build rewrite system for generic signature; concrete nesting limit exceeded}}
292
+ // expected-note@+1 {{failed rewrite rule is τ_0_0.[P2:Assoc1].[concrete: ((((((((((((((((((((((((((((((τ_0_0.[P2:Assoc1], τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1), τ_0_1)] => τ_0_0.[P2:Assoc1]}}
292
293
func structuralSameTypeRecursive1< T: P2 , U> ( _: T , _: U )
293
- where T. Assoc1 == Tuple2 < T . Assoc1 , U > // expected-error{{same-type constraint 'T.Assoc1' == '(T.Assoc1, U)' is recursive}}
294
+ where T. Assoc1 == Tuple2 < T . Assoc1 , U >
295
+ // expected-error@-1 {{'Assoc1' is not a member type of type 'T'}}
296
+ // expected-error@-2 {{'Assoc1' is not a member type of type 'T'}}
294
297
{ }
295
298
296
299
protocol P3 {
@@ -302,7 +305,7 @@ protocol P4 {
302
305
303
306
// CHECK-LABEL: same_types.(file).test9@
304
307
// CHECK-NEXT: Generic signature: <T where T : P4>
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'}}
308
+ func test9< T> ( _: T ) where T. A == X , T: P4 , T. A: P3 { } // expected-error{{no type for 'T.A' can satisfy both 'T.A == X' and 'T.A : P3'}}
306
309
307
310
// Same-type constraint conflict through protocol where clauses.
308
311
protocol P5 where Foo1 == Foo2 {
@@ -320,9 +323,9 @@ struct X5b { }
320
323
321
324
// CHECK-LABEL: same_types.(file).test9(_:u:)@
322
325
// CHECK-NEXT: Generic signature: <T, U where T : P6, U : P6, T.[P6]Bar == U.[P6]Bar>
323
- func test9< T: P6 , U: P6 > ( _ t: T , u: U )
324
- where T. Bar. Foo1 == X5a , // expected-note{{same-type constraint 'T.Bar.Foo1' == 'X5a' written here}}
325
- U. Bar. Foo2 == X5b , // expected-error{{'U.Bar.Foo2' cannot be equal to both 'X5b' and 'X5a'}}
326
+ func test9< T: P6 , U: P6 > ( _ t: T , u: U ) // expected-error{{no type for 'T.Bar.Foo1' can satisfy both 'T.Bar.Foo1 == X5a' and 'T.Bar.Foo1 == X5b'}}
327
+ where T. Bar. Foo1 == X5a ,
328
+ U. Bar. Foo2 == X5b ,
326
329
T. Bar == U . Bar {
327
330
}
328
331
@@ -333,14 +336,14 @@ func test9<T: P6, U: P6>(_ t: T, u: U)
333
336
// CHECK-NEXT: Generic signature: <T, U where T == U>
334
337
func testMetatypeSameType< T, U> ( _ t: T , _ u: U )
335
338
where T. Type == U . Type { }
336
- // expected-error@-1 {{same-type requirement makes generic parameters 'T ' and 'U ' equivalent}}
337
- // expected-warning@-2{{neither type in same-type constraint ( 'T.Type' or 'U.Type') refers to a generic parameter or associated type }}
339
+ // expected-warning@-2 {{same-type requirement makes generic parameters 'U ' and 'T ' equivalent}}
340
+ // expected-warning@-2{{redundant same-type constraint 'T.Type' == 'U.Type'}}
338
341
339
342
// CHECK-LABEL: same_types.(file).testSameTypeCommutativity1@
340
343
// CHECK-NEXT: Generic signature: <U, T where U == T.Type>
341
344
func testSameTypeCommutativity1< U, T> ( _ t: T , _ u: U )
342
345
where T. Type == U { } // Equivalent to U == T.Type
343
- // expected-error@-1 {{same-type requirement makes generic parameter 'U' non-generic}}
346
+ // expected-warning@-2 {{same-type requirement makes generic parameter 'U' non-generic}}
344
347
345
348
// CHECK-LABEL: same_types.(file).testSameTypeCommutativity2@
346
349
// CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == U?>
@@ -356,7 +359,7 @@ func testSameTypeCommutativity3<U, T: P1>(_ t: T, _ u: U)
356
359
// CHECK-NEXT: Generic signature: <U, T where T == (U) -> ()>
357
360
func testSameTypeCommutativity4< U, T> ( _ t: T , _ u: U )
358
361
where ( U ) -> ( ) == T { } // Equivalent to T == (U) -> ()
359
- // expected-error@-1 {{same-type requirement makes generic parameter 'T' non-generic}}
362
+ // expected-warning@-2 {{same-type requirement makes generic parameter 'T' non-generic}}
360
363
361
364
// CHECK-LABEL: same_types.(file).testSameTypeCommutativity5@
362
365
// CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == P3 & PPP>
@@ -381,8 +384,6 @@ struct Bar<A: P1, B: P1> where A.Assoc == B.Assoc {
381
384
// CHECK-LABEL: same_types.(file).Bar.f(with:)@
382
385
// 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>
383
386
func f< C: P1 > ( with other: C ) -> Foo < A , B , C > where A. Assoc == C . Assoc {
384
- // expected-note@-1 {{previous same-type constraint 'B.Assoc' == 'C.Assoc' inferred from type here}}
385
- // expected-warning@-2 {{redundant same-type constraint 'A.Assoc' == 'C.Assoc'}}
386
387
fatalError ( )
387
388
}
388
389
}
0 commit comments