11// RUN: %target-typecheck-verify-swift
22
3- struct K < U> { } // expected-note 6{{'U' declared as parameter to type 'K'}}
3+ struct K < U> { }
44protocol Q { }
5+ struct ConformingType : Q { }
56
67struct S1 < T: Q > : ExpressibleByArrayLiteral { // expected-note 2{{where 'T' = 'K<Int>'}}
78 init ( _ x: T ) { }
89 init ( arrayLiteral: T ... ) { }
910}
1011
11- typealias R1 < T: Q > = S1 < T > // expected-note {{where 'T' = 'K<Int>'}} expected-note 2{{where 'T' = 'K<U >'}}
12+ typealias R1 < T: Q > = S1 < T > // expected-note 2{{where 'T' = 'K<Int >'}}
1213
1314func foo( _ x: K < Int > ) {
1415 let _ = [ x] as S1 < K > // expected-error {{generic struct 'S1' requires that 'K<Int>' conform to 'Q'}}
1516 let _ = [ x] as R1 < K > // expected-error {{generic type alias 'R1' requires that 'K<Int>' conform to 'Q'}}
1617
17- let _: S1 < K > = [ x] // expected-error {{generic struct 'S1' requires that 'K<Int>' conform to 'Q'}}
18- // FIXME: We ought to be able to infer 'U' here.
19- let _: R1 < K > = [ x] // expected-error 2 {{generic type alias 'R1' requires that 'K<U>' conform to 'Q'}}
20- // expected-error@-1 2 {{generic parameter 'U' could not be inferred}}
18+ let _: S1 < K > = [ x] // expected-error {{generic struct 'S1' requires that 'K<Int>' conform to 'Q'}}
19+ let _: R1 < K > = [ x] // expected-error {{generic type alias 'R1' requires that 'K<Int>' conform to 'Q'}}
2120}
2221
2322protocol P2 {
2423 associatedtype A
2524}
2625
2726struct S2 < A: Q > : P2 { } // expected-note 3{{where 'A' = 'K<Int>'}}
28- typealias R2 < A: Q > = S2 < A > // expected-note 2 {{where 'A' = 'K<Int>'}} expected-note 2{{where 'A' = 'K<U >'}}
27+ typealias R2 < A: Q > = S2 < A > // expected-note 3 {{where 'A' = 'K<Int>'}}
2928
3029// Same as S2, but without the Q requirement.
3130struct S3 < A> : P2 { }
32- typealias R3 < A: Q > = S3 < A > // expected-note {{where 'A' = 'K<Int>'}} expected-note {{where 'A' = 'K<U >'}}
31+ typealias R3 < A: Q > = S3 < A > // expected-note 2 {{where 'A' = 'K<Int>'}}
3332
3433func foo< T: P2 > ( _ y: T . A . Type ) -> T { }
3534let _ = foo ( K< Int> . self ) as S2 < K > // expected-error {{generic struct 'S2' requires that 'K<Int>' conform to 'Q'}}
3635let _ = foo ( K< Int> . self ) as R2 < K > // expected-error {{generic type alias 'R2' requires that 'K<Int>' conform to 'Q'}}
3736let _ = foo ( K< Int> . self ) as R3 < K > // expected-error {{generic type alias 'R3' requires that 'K<Int>' conform to 'Q'}}
3837
3938let _: S2 < K > = foo ( K< Int> . self ) // expected-error {{generic struct 'S2' requires that 'K<Int>' conform to 'Q'}}
40- // FIXME: We ought to be able to infer 'U' here.
41- let _: R2 < K > = foo ( K< Int> . self ) // expected-error 2{{generic type alias 'R2' requires that 'K<U>' conform to 'Q'}}
42- // expected-error@-1 2 {{generic parameter 'U' could not be inferred}}
43- let _: R3 < K > = foo ( K< Int> . self ) // expected-error {{generic type alias 'R3' requires that 'K<U>' conform to 'Q'}}
44- // expected-error@-1 2 {{generic parameter 'U' could not be inferred}}
39+ let _: R2 < K > = foo ( K< Int> . self ) // expected-error {{generic type alias 'R2' requires that 'K<Int>' conform to 'Q'}}
40+ let _: R3 < K > = foo ( K< Int> . self ) // expected-error {{generic type alias 'R3' requires that 'K<Int>' conform to 'Q'}}
4541
4642func foo< T: P2 > ( _ x: T . Type , _ y: T . A . Type ) { }
4743foo ( S2< _> . self , K< Int> . self ) // expected-error {{generic struct 'S2' requires that 'K<Int>' conform to 'Q'}}
@@ -52,3 +48,17 @@ struct S4<T: Q> { // expected-note {{where 'T' = 'Int'}}
5248}
5349
5450_ = S4 < _ > ( 0 ) // expected-error {{generic struct 'S4' requires that 'Int' conform to 'Q'}}
51+
52+ func testLocalOuterGeneric< T> ( _ x: T ) {
53+ typealias X < U: Q > = ( T , U ) // expected-note {{where 'U' = 'String'}}
54+ let _: X < _ > = ( x, " " ) // expected-error {{generic type alias 'X' requires that 'String' conform to 'Q'}}
55+ let _: X < _ > = ( x, ConformingType ( ) )
56+ }
57+
58+ struct TestParentGeneric < T> {
59+ typealias X < U: Q > = ( T , U ) // expected-note {{where 'U' = 'String'}}
60+ func bar( _ x: T ) {
61+ let _: X < _ > = ( x, " " ) // expected-error {{generic type alias 'X' requires that 'String' conform to 'Q'}}
62+ let _: X < _ > = ( x, ConformingType ( ) )
63+ }
64+ }
0 commit comments