11// RUN: %target-typecheck-verify-swift
2- // REQUIRES: rdar160135085
32
4- struct K < U> { } // expected-note 6{{'U' declared as parameter to type 'K'}}
3+ struct K < U> { }
54protocol Q { }
5+ struct ConformingType : Q { }
66
77struct S1 < T: Q > : ExpressibleByArrayLiteral { // expected-note 2{{where 'T' = 'K<Int>'}}
88 init ( _ x: T ) { }
99 init ( arrayLiteral: T ... ) { }
1010}
1111
12- 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 >'}}
1313
1414func foo( _ x: K < Int > ) {
1515 let _ = [ x] as S1 < K > // expected-error {{generic struct 'S1' requires that 'K<Int>' conform to 'Q'}}
1616 let _ = [ x] as R1 < K > // expected-error {{generic type alias 'R1' requires that 'K<Int>' conform to 'Q'}}
1717
18- let _: S1 < K > = [ x] // expected-error {{generic struct 'S1' requires that 'K<Int>' conform to 'Q'}}
19- // FIXME: We ought to be able to infer 'U' here.
20- let _: R1 < K > = [ x] // expected-error 2 {{generic type alias 'R1' requires that 'K<U>' conform to 'Q'}}
21- // 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'}}
2220}
2321
2422protocol P2 {
2523 associatedtype A
2624}
2725
2826struct S2 < A: Q > : P2 { } // expected-note 3{{where 'A' = 'K<Int>'}}
29- 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>'}}
3028
3129// Same as S2, but without the Q requirement.
3230struct S3 < A> : P2 { }
33- 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>'}}
3432
3533func foo< T: P2 > ( _ y: T . A . Type ) -> T { }
3634let _ = foo ( K< Int> . self ) as S2 < K > // expected-error {{generic struct 'S2' requires that 'K<Int>' conform to 'Q'}}
3735let _ = foo ( K< Int> . self ) as R2 < K > // expected-error {{generic type alias 'R2' requires that 'K<Int>' conform to 'Q'}}
3836let _ = foo ( K< Int> . self ) as R3 < K > // expected-error {{generic type alias 'R3' requires that 'K<Int>' conform to 'Q'}}
3937
4038let _: S2 < K > = foo ( K< Int> . self ) // expected-error {{generic struct 'S2' requires that 'K<Int>' conform to 'Q'}}
41- // FIXME: We ought to be able to infer 'U' here.
42- let _: R2 < K > = foo ( K< Int> . self ) // expected-error 2{{generic type alias 'R2' requires that 'K<U>' conform to 'Q'}}
43- // expected-error@-1 2 {{generic parameter 'U' could not be inferred}}
44- let _: R3 < K > = foo ( K< Int> . self ) // expected-error {{generic type alias 'R3' requires that 'K<U>' conform to 'Q'}}
45- // 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'}}
4641
4742func foo< T: P2 > ( _ x: T . Type , _ y: T . A . Type ) { }
4843foo ( S2< _> . self , K< Int> . self ) // expected-error {{generic struct 'S2' requires that 'K<Int>' conform to 'Q'}}
@@ -53,3 +48,17 @@ struct S4<T: Q> { // expected-note {{where 'T' = 'Int'}}
5348}
5449
5550_ = 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