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