1
1
// RUN: %target-typecheck-verify-swift
2
2
3
- struct K < U> { } // expected-note 6{{'U' declared as parameter to type 'K'}}
3
+ struct K < U> { }
4
4
protocol Q { }
5
+ struct ConformingType : Q { }
5
6
6
7
struct S1 < T: Q > : ExpressibleByArrayLiteral { // expected-note 2{{where 'T' = 'K<Int>'}}
7
8
init ( _ x: T ) { }
8
9
init ( arrayLiteral: T ... ) { }
9
10
}
10
11
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 >'}}
12
13
13
14
func foo( _ x: K < Int > ) {
14
15
let _ = [ x] as S1 < K > // expected-error {{generic struct 'S1' requires that 'K<Int>' conform to 'Q'}}
15
16
let _ = [ x] as R1 < K > // expected-error {{generic type alias 'R1' requires that 'K<Int>' conform to 'Q'}}
16
17
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'}}
21
20
}
22
21
23
22
protocol P2 {
24
23
associatedtype A
25
24
}
26
25
27
26
struct 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>'}}
29
28
30
29
// Same as S2, but without the Q requirement.
31
30
struct 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>'}}
33
32
34
33
func foo< T: P2 > ( _ y: T . A . Type ) -> T { }
35
34
let _ = foo ( K< Int> . self ) as S2 < K > // expected-error {{generic struct 'S2' requires that 'K<Int>' conform to 'Q'}}
36
35
let _ = foo ( K< Int> . self ) as R2 < K > // expected-error {{generic type alias 'R2' requires that 'K<Int>' conform to 'Q'}}
37
36
let _ = foo ( K< Int> . self ) as R3 < K > // expected-error {{generic type alias 'R3' requires that 'K<Int>' conform to 'Q'}}
38
37
39
38
let _: 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'}}
45
41
46
42
func foo< T: P2 > ( _ x: T . Type , _ y: T . A . Type ) { }
47
43
foo ( 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'}}
52
48
}
53
49
54
50
_ = 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