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
23
34protocol Fooable {
45 associatedtype Foo // expected-note{{protocol requires nested type 'Foo'; do you want to add it?}}
@@ -38,23 +39,31 @@ struct NestedConstraint<T> {
3839 }
3940}
4041
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>
4144func test2< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
4245 where T. Foo == X , U. Foo == T . Foo {
4346 return ( t. foo, u. foo)
4447}
4548
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>
4651func test2a< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
4752 where T. Foo == X , T. Foo == U . Foo {
4853 return ( t. foo, u. foo)
4954}
5055
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>
5158func test3< T: Fooable , U: Fooable > ( _ t: T , u: U ) -> ( X , X )
5259 where T. Foo == X , U. Foo == X , T. Foo == U . Foo {
5360 // expected-warning@-1{{redundant same-type constraint 'U.Foo' == 'X'}}
5461 // expected-note@-2{{same-type constraint 'T.Foo' == 'X' written here}}
5562 return ( t. foo, u. foo)
5663}
5764
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>
5867func fail1<
5968 T: Fooable , U: Fooable
6069> ( _ t: T , u: U ) -> ( X , Y )
@@ -63,6 +72,8 @@ func fail1<
6372 return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type '(X, X)' to return type '(X, Y)'}}
6473}
6574
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>
6677func fail2<
6778 T: Fooable , U: Fooable
6879> ( _ t: T , u: U ) -> ( X , Y )
@@ -75,6 +86,8 @@ func test4<T: Barrable>(_ t: T) -> Y where T.Bar == Y {
7586 return t. bar
7687}
7788
89+ // CHECK-LABEL: same_types.(file).fail3@
90+ // CHECK-NEXT: Generic signature: <T where T : Barrable>
7891func fail3< T: Barrable > ( _ t: T ) -> X
7992 where T. Bar == X { // expected-error {{'X' does not conform to required protocol 'Fooable'}}
8093 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 {
88101 return ( t. bar, t. bar. foo)
89102}
90103
104+ // CHECK-LABEL: same_types.(file).test7@
105+ // CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
91106func test7< T: Barrable > ( _ t: T ) -> ( Y , X ) where T. Bar == Y , T. Bar. Foo == X {
92107 // expected-warning@-1{{neither type in same-type constraint ('Y.Foo' (aka 'X') or 'X') refers to a generic parameter or associated type}}
93108 return ( t. bar, t. bar. foo)
94109}
95110
111+ // CHECK-LABEL: same_types.(file).fail4@
112+ // CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
96113func fail4< T: Barrable > ( _ t: T ) -> ( Y , Z )
97114 where
98115 T. Bar == Y ,
99116 T. Bar. Foo == Z { // expected-error{{generic signature requires types 'Y.Foo' (aka 'X') and 'Z' to be the same}}
100117 return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type '(Y, X)' to return type '(Y, Z)'}}
101118}
102119
120+ // CHECK-LABEL: same_types.(file).fail5@
121+ // CHECK-NEXT: Generic signature: <T where T : Barrable, T.[Barrable]Bar == Y>
103122func fail5< T: Barrable > ( _ t: T ) -> ( Y , Z )
104123 where
105124 T. Bar. Foo == Z , // expected-note{{same-type constraint 'T.Bar.Foo' == 'Z' written here}}
106125 T. Bar == Y { // expected-error{{'T.Bar.Foo' cannot be equal to both 'Y.Foo' (aka 'X') and 'Z'}}
107126 return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type '(Y, X)' to return type '(Y, Z)'}}
108127}
109128
129+ // CHECK-LABEL: same_types.(file).test8@
130+ // CHECK-NEXT: Generic signature: <T where T : Fooable>
110131func test8< T: Fooable > ( _ t: T )
111132 where T. Foo == X , // expected-note{{same-type constraint 'T.Foo' == 'X' written here}}
112133 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
121142 return t
122143}
123144
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>
124147func test8< T: Barrable , U: Barrable > ( _ t: T , u: U ) -> ( Y , Y , X , X )
125148 where T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
126149 U. Bar. Foo == X , T. Bar == U . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
127150 return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
128151}
129152
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>
130155func test8a< T: Barrable , U: Barrable > ( _ t: T , u: U ) -> ( Y , Y , X , X )
131156 where
132157 T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
133158 U. Bar. Foo == X , U. Bar == T . Bar { // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
134159 return ( t. bar, u. bar, t. bar. foo, u. bar. foo)
135160}
136161
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>
137164func test8b< T: Barrable , U: Barrable > ( _ t: T , u: U )
138165 where U. Bar. Foo == X , // expected-warning{{redundant same-type constraint 'U.Bar.Foo' == 'X'}}
139166 T. Bar == Y , // expected-note{{same-type constraint 'U.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
@@ -166,6 +193,8 @@ struct Q : P {
166193}
167194
168195struct 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>
169198 func foo< X, Y> ( x: X , y: Y ) where X == T . A , Y == T . B {
170199 print ( X . self)
171200 print ( Y . self)
@@ -176,6 +205,8 @@ struct S1<T : P> {
176205S1 < Q > ( ) . foo ( x: 1 , y: 2 )
177206
178207struct 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>
179210 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}}
180211 print ( X . self)
181212 print ( Y . self)
@@ -186,6 +217,8 @@ struct S2<T : P> where T.A == T.B {
186217S2 < Q > ( ) . foo ( x: 1 , y: 2 )
187218
188219struct 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>
189222 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}}
190223}
191224S3 < Q > ( ) . foo ( x: 1 , y: 2 )
@@ -208,6 +241,8 @@ struct QQ : P {
208241}
209242
210243struct 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>
211246 func foo< X : PP > ( x: X ) where X. A == T . A {
212247 print ( x)
213248 print ( X . self)
@@ -223,18 +258,24 @@ protocol P1 {
223258 associatedtype Assoc
224259}
225260
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>>
226263func structuralSameType1< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
227264 where A. Assoc == X1 < T , U > , B. Assoc == X1 < V , W > , A. Assoc == B . Assoc { }
228265// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'V' equivalent}}
229266// expected-error@-2{{same-type requirement makes generic parameters 'U' and 'W' equivalent}}
230267
231268typealias Tuple2 < T, U> = ( T , U )
232269
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)>
233272func structuralSameType2< A: P1 , B: P1 , T, U, V, W> ( _: A , _: B , _: T , _: U , _: V , _: W )
234273 where A. Assoc == Tuple2 < T , U > , B. Assoc == Tuple2 < V , W > , A. Assoc == B . Assoc { }
235274// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'V' equivalent}}
236275// expected-error@-2{{same-type requirement makes generic parameters 'U' and 'W' equivalent}}
237276
277+ // CHECK-LABEL: same_types.(file).structuralSameType3@
278+ // CHECK-NEXT: Generic signature: <T, U, V, W where T == V, U == W>
238279func structuralSameType3< T, U, V, W> ( _: T , _: U , _: V , _: W )
239280 where X1 < T , U > == X1 < V , W > { }
240281// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'V' equivalent}}
@@ -246,6 +287,8 @@ protocol P2 {
246287 associatedtype Assoc2
247288}
248289
290+ // CHECK-LABEL: same_types.(file).structuralSameTypeRecursive1@
291+ // CHECK-NEXT: Generic signature: <T, U>
249292func structuralSameTypeRecursive1< T: P2 , U> ( _: T , _: U )
250293 where T. Assoc1 == Tuple2 < T . Assoc1 , U > // expected-error{{same-type constraint 'T.Assoc1' == '(T.Assoc1, U)' is recursive}}
251294{ }
@@ -257,6 +300,8 @@ protocol P4 {
257300 associatedtype A
258301}
259302
303+ // CHECK-LABEL: same_types.(file).test9@
304+ // CHECK-NEXT: Generic signature: <T where T : P4>
260305func 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'}}
261306
262307// Same-type constraint conflict through protocol where clauses.
@@ -273,6 +318,8 @@ struct X5a {}
273318
274319struct X5b { }
275320
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>
276323func test9< T: P6 , U: P6 > ( _ t: T , u: U )
277324 where T. Bar. Foo1 == X5a , // expected-note{{same-type constraint 'T.Bar.Foo1' == 'X5a' written here}}
278325 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)
282329// FIXME: Remove -verify-ignore-unknown.
283330// <unknown>:0: error: unexpected error produced: generic parameter τ_0_0.Bar.Foo cannot be equal to both 'Y.Foo' (aka 'X') and 'Z'
284331
332+ // CHECK-LABEL: same_types.(file).testMetatypeSameType@
333+ // CHECK-NEXT: Generic signature: <T, U where T == U>
285334func testMetatypeSameType< T, U> ( _ t: T , _ u: U )
286335 where T. Type == U . Type { }
287336// expected-error@-1{{same-type requirement makes generic parameters 'T' and 'U' equivalent}}
288337// expected-warning@-2{{neither type in same-type constraint ('T.Type' or 'U.Type') refers to a generic parameter or associated type}}
289338
339+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity1@
340+ // CHECK-NEXT: Generic signature: <U, T where U == T.Type>
290341func testSameTypeCommutativity1< U, T> ( _ t: T , _ u: U )
291342 where T. Type == U { } // Equivalent to U == T.Type
292343// expected-error@-1{{same-type requirement makes generic parameter 'U' non-generic}}
293344
345+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity2@
346+ // CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == U?>
294347func testSameTypeCommutativity2< U, T: P1 > ( _ t: T , _ u: U )
295348 where U ? == T . Assoc { } // Ok, equivalent to T.Assoc == U?
296349
350+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity3@
351+ // CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == (U) -> ()>
297352func testSameTypeCommutativity3< U, T: P1 > ( _ t: T , _ u: U )
298353 where ( U ) -> ( ) == T . Assoc { } // Ok, equivalent to T.Assoc == (U) -> ()
299354
355+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity4@
356+ // CHECK-NEXT: Generic signature: <U, T where T == (U) -> ()>
300357func testSameTypeCommutativity4< U, T> ( _ t: T , _ u: U )
301358 where ( U ) -> ( ) == T { } // Equivalent to T == (U) -> ()
302359// expected-error@-1{{same-type requirement makes generic parameter 'T' non-generic}}
303360
361+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity5@
362+ // CHECK-NEXT: Generic signature: <U, T where T : P1, T.[P1]Assoc == P3 & PPP>
304363func testSameTypeCommutativity5< U, T: P1 > ( _ t: T , _ u: U )
305364 where PPP & P3 == T . Assoc { } // Ok, equivalent to T.Assoc == PPP & P3
306365
366+ // CHECK-LABEL: same_types.(file).testSameTypeCommutativity6@
367+ // CHECK-NEXT: Generic signature: <U, T where T : P1>
307368func testSameTypeCommutativity6< U, T: P1 > ( _ t: T , _ u: U )
308369 where U & P3 == T . Assoc { } // Equivalent to T.Assoc == U & P3
309370// expected-error@-1 {{non-protocol, non-class type 'U' cannot be used within a protocol-constrained type}}
310371
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>
312376struct Foo < A: P1 , B: P1 , C: P1 > where A. Assoc == B . Assoc , A. Assoc == C . Assoc { }
313377
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>
314380struct 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>
315383 func f< C: P1 > ( with other: C ) -> Foo < A , B , C > where A. Assoc == C . Assoc {
316384 // expected-note@-1 {{previous same-type constraint 'B.Assoc' == 'C.Assoc' inferred from type here}}
317385 // expected-warning@-2 {{redundant same-type constraint 'A.Assoc' == 'C.Assoc'}}
0 commit comments