1- // RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=off
1+ // RUN: %target-typecheck-verify-swift -requirement-machine-inferred-signatures=on
22// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
33
44protocol Fooable {
@@ -57,29 +57,26 @@ func test2a<T: Fooable, U: Fooable>(_ t: T, u: U) -> (X, X)
5757// CHECK-NEXT: Generic signature: <T, U where T : Fooable, U : Fooable, T.[Fooable]Foo == X, U.[Fooable]Foo == X>
5858func test3< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
5959 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'}}
6261 return ( t. foo, u. foo)
6362}
6463
6564// CHECK-LABEL: same_types.(file).fail1(_:u:)@
6665// 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'}}
6867 T: Fooable , U: Fooable
6968> ( _ 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)'}}
7371}
7472
7573// CHECK-LABEL: same_types.(file).fail2(_:u:)@
7674// 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'}}
7876 T: Fooable , U: Fooable
7977> ( _ 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)'}}
8380}
8481
8582func 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 {
8885
8986// CHECK-LABEL: same_types.(file).fail3@
9087// 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 {
9390 return t. bar // expected-error{{cannot convert return expression of type 'T.Bar' }}
9491}
9592
@@ -104,7 +101,7 @@ func test6<T: Barrable>(_ t: T) -> (Y, X) where T.Bar == Y {
104101// CHECK-LABEL: same_types.(file).test7@
105102// CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
106103func 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'}}
108105 return ( t. bar, t. bar. foo)
109106}
110107
@@ -121,31 +118,31 @@ func fail4<T: Barrable>(_ t: T) -> (Y, Z)
121118// CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
122119func fail5< T: Barrable > ( _ t: T ) -> ( Y , Z )
123120 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 {
126123 return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type '(Y, X)' to return type '(Y, Z)'}}
127124}
128125
129126// CHECK-LABEL: same_types.(file).test8@
130127// 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 { }
134131
135132
136133func testAssocTypeEquivalence< T: Fooable > ( _ fooable: T ) -> X . Type
137134 where T. Foo == X {
138135 return T . Foo. self
139136}
140137
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}}
142139 return t
143140}
144141
145142// CHECK-LABEL: same_types.(file).test8(_:u:)@
146143// CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
147144func 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 ,
149146 U. Bar. Foo == X , T. Bar == U . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
150147 return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
151148}
@@ -154,7 +151,7 @@ func test8<T: Barrable, U: Barrable>(_ t: T, u: U) -> (Y, Y, X, X)
154151// CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
155152func test8a< T: Barrable , U: Barrable > ( _ t: T , u: U ) -> ( Y , Y , X , X )
156153 where
157- T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
154+ T. Bar == Y ,
158155 U. Bar. Foo == X , U. Bar == T . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
159156 return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
160157}
@@ -163,7 +160,7 @@ func test8a<T: Barrable, U: Barrable>(_ t: T, u: U) -> (Y, Y, X, X)
163160// CHECK-NEXT: Generic signature: <T, U where T : Barrable, U : Barrable, T.[Barrable]Bar == Y, U.[Barrable]Bar == Y>
164161func test8b< T: Barrable , U: Barrable > ( _ t: T , u: U )
165162 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 ,
167164 T. Bar == U . Bar {
168165}
169166
@@ -207,7 +204,8 @@ S1<Q>().foo(x: 1, y: 2)
207204struct S2 < T : P > where T. A == T . B {
208205 // CHECK-LABEL: same_types.(file).S2.foo(x:y:)@
209206 // 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'}}
211209 print ( X . self)
212210 print ( Y . self)
213211 print ( x)
@@ -219,7 +217,7 @@ S2<Q>().foo(x: 1, y: 2)
219217struct S3 < T : P > {
220218 // CHECK-LABEL: same_types.(file).S3.foo(x:y:)@
221219 // 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}}
223221}
224222S3 < Q > ( ) . foo ( x: 1 , y: 2 )
225223
@@ -262,25 +260,25 @@ protocol P1 {
262260// 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>>
263261func structuralSameType1< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
264262 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}}
267265
268266typealias Tuple2 < T, U> = ( T , U )
269267
270268// CHECK-LABEL: same_types.(file).structuralSameType2@
271269// 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)>
272270func structuralSameType2< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
273271 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}}
276274
277275// CHECK-LABEL: same_types.(file).structuralSameType3@
278276// CHECK-NEXT: Generic signature: <T, U, V, W where T == V, U == W>
279277func structuralSameType3< T, U, V, W> ( _: T , _: U , _: V , _: W )
280278 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>'}}
284282
285283protocol P2 {
286284 associatedtype Assoc1
@@ -289,8 +287,13 @@ protocol P2 {
289287
290288// CHECK-LABEL: same_types.(file).structuralSameTypeRecursive1@
291289// 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]}}
292293func 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'}}
294297{ }
295298
296299protocol P3 {
@@ -302,7 +305,7 @@ protocol P4 {
302305
303306// CHECK-LABEL: same_types.(file).test9@
304307// 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'}}
306309
307310// Same-type constraint conflict through protocol where clauses.
308311protocol P5 where Foo1 == Foo2 {
@@ -320,9 +323,9 @@ struct X5b { }
320323
321324// CHECK-LABEL: same_types.(file).test9(_:u:)@
322325// 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 ,
326329 T. Bar == U . Bar {
327330}
328331
@@ -333,14 +336,14 @@ func test9<T: P6, U: P6>(_ t: T, u: U)
333336// CHECK-NEXT: Generic signature: <T, U where T == U>
334337func testMetatypeSameType< T, U> ( _ t: T , _ u: U )
335338 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'}}
338341
339342// CHECK-LABEL: same_types.(file).testSameTypeCommutativity1@
340343// CHECK-NEXT: Generic signature: <U, T where U == T.Type>
341344func testSameTypeCommutativity1< U, T> ( _ t: T , _ u: U )
342345 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}}
344347
345348// CHECK-LABEL: same_types.(file).testSameTypeCommutativity2@
346349// 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)
356359// CHECK-NEXT: Generic signature: <U, T where T == (U) -> ()>
357360func testSameTypeCommutativity4< U, T> ( _ t: T , _ u: U )
358361 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}}
360363
361364// CHECK-LABEL: same_types.(file).testSameTypeCommutativity5@
362365// 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 {
381384 // CHECK-LABEL: same_types.(file).Bar.f(with:)@
382385 // 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>
383386 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'}}
386387 fatalError ( )
387388 }
388389}
0 commit comments