@@ -58,14 +58,16 @@ func test3<T: Fooable, U: Fooable>(_ t: T, u: U) -> (X, X)
58
58
func fail1<
59
59
T: Fooable , U: Fooable
60
60
> ( _ t: T , u: U ) -> ( X , Y )
61
- where T. Foo == X , U. Foo == Y , T. Foo == U . Foo { // expected-error{{associated type 'T.Foo' cannot be equal to both 'X' and 'Y'}}
61
+ where T. Foo == X , U. Foo == Y , T. Foo == U . Foo { // expected-error{{'U.Foo' cannot be equal to both 'Y' and 'X'}}
62
+ // expected-note@-1{{same-type constraint 'T.Foo' == 'X' written here}}
62
63
return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type 'X' to return type 'Y'}}
63
64
}
64
65
65
66
func fail2<
66
67
T: Fooable , U: Fooable
67
68
> ( _ t: T , u: U ) -> ( X , Y )
68
- where T. Foo == U . Foo , T. Foo == X , U. Foo == Y { // expected-error{{associated type 'U.Foo' cannot be equal to both 'X' and 'Y'}}
69
+ where T. Foo == U . Foo , T. Foo == X , U. Foo == Y { // expected-error{{'U.Foo' cannot be equal to both 'Y' and 'X'}}
70
+ // expected-note@-1{{same-type constraint 'T.Foo' == 'X' written here}}
69
71
return ( t. foo, u. foo) // expected-error{{cannot convert return expression of type 'X' to return type 'Y'}}
70
72
}
71
73
@@ -94,20 +96,22 @@ func test7<T: Barrable>(_ t: T) -> (Y, X) where T.Bar == Y, T.Bar.Foo == X {
94
96
95
97
func fail4< T: Barrable > ( _ t: T ) -> ( Y , Z )
96
98
where
97
- T. Bar == Y ,
98
- T. Bar. Foo == Z { // expected-error{{associated type 'T.Bar.Foo' cannot be equal to both 'Y.Foo' (aka 'X') and 'Z' }}
99
+ T. Bar == Y , // expected-note{{same-type constraint 'T.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
100
+ T. Bar. Foo == Z { // expected-error{{'T.Bar.Foo' cannot be equal to both 'Z' and ' Y.Foo' (aka 'X')}}
99
101
return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type 'X' to return type 'Z'}}
100
102
}
101
103
102
104
func fail5< T: Barrable > ( _ t: T ) -> ( Y , Z )
103
105
where
104
- T. Bar. Foo == Z , // expected-warning{{redundant same-type constraint 'T.Bar.Foo' == 'Z'}}
105
- T. Bar == Y { // expected-error{{associated type 'T.Bar.Foo' cannot be equal to both 'Z' and 'X'}}
106
- // expected-note@-1{{same-type constraint 'T.Bar.Foo' == 'Y.Foo' (aka 'X') implied here}}
106
+ T. Bar. Foo == Z , // expected-note{{same-type constraint 'T.Bar.Foo' == 'Z' written here}}
107
+ T. Bar == Y { // expected-error{{'T.Bar.Foo' cannot be equal to both 'Y.Foo' (aka 'X') and 'Z'}}
107
108
return ( t. bar, t. bar. foo) // expected-error{{cannot convert return expression of type 'X' to return type 'Z'}}
108
109
}
109
110
110
- func test8< T: Fooable > ( _ t: T ) where T. Foo == X , T. Foo == Y { } // expected-error{{associated type 'T.Foo' cannot be equal to both 'X' and 'Y'}}
111
+ func test8< T: Fooable > ( _ t: T )
112
+ where T. Foo == X , // expected-note{{same-type constraint 'T.Foo' == 'X' written here}}
113
+ T. Foo == Y { } // expected-error{{'T.Foo' cannot be equal to both 'Y' and 'X'}}
114
+
111
115
112
116
func testAssocTypeEquivalence< T: Fooable > ( _ fooable: T ) -> X . Type
113
117
where T. Foo == X {
@@ -246,7 +250,6 @@ func structuralSameTypeRecursive1<T: P2, U>(_: T, _: U)
246
250
where T. Assoc1 == Tuple2 < T . Assoc1 , U > // expected-error{{same-type constraint 'T.Assoc1' == '(T.Assoc1, U)' is recursive}}
247
251
{ }
248
252
249
-
250
253
protocol P3 {
251
254
}
252
255
@@ -256,5 +259,25 @@ protocol P4 {
256
259
257
260
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'}}
258
261
262
+ // Same-type constraint conflict through protocol where clauses.
263
+ protocol P5 where Foo1 == Foo2 {
264
+ associatedtype Foo1
265
+ associatedtype Foo2
266
+ }
267
+
268
+ protocol P6 {
269
+ associatedtype Bar : P5
270
+ }
271
+
272
+ struct X5a { }
273
+
274
+ struct X5b { }
275
+
276
+ func test9< T: P6 , U: P6 > ( _ t: T , u: U )
277
+ where T. Bar. Foo1 == X5a , // expected-note{{same-type constraint 'T.Bar.Foo1' == 'X5a' written here}}
278
+ U. Bar. Foo2 == X5b , // expected-error{{'U.Bar.Foo2' cannot be equal to both 'X5b' and 'X5a'}}
279
+ T. Bar == U . Bar {
280
+ }
281
+
259
282
// FIXME: Remove -verify-ignore-unknown.
260
283
// <unknown>:0: error: unexpected error produced: generic parameter τ_0_0.Bar.Foo cannot be equal to both 'Y.Foo' (aka 'X') and 'Z'
0 commit comments