1
- // RUN: %target-run-simple-swift | FileCheck %s
1
+ // RUN: mkdir -p %t
2
+ // RUN: %target-build-swift %s -Xfrontend -enable-experimental-nested-generic-types -o %t/a.out
3
+ // RUN: %target-run %t/a.out | FileCheck %s
2
4
// REQUIRES: executable_test
3
5
4
6
protocol MyPrintable {
5
7
func print( )
6
8
}
7
9
8
- struct PrintableValue : MyPrintable {
9
- init ( _ value : String ) {
10
- self . value = value
10
+ extension Int : MyPrintable {
11
+ func print ( ) {
12
+ Swift . print ( self , terminator : " " )
11
13
}
14
+ }
12
15
16
+ extension String : MyPrintable {
13
17
func print( ) {
14
- Swift . print ( value , terminator: " " )
18
+ Swift . print ( self , terminator: " " )
15
19
}
20
+ }
16
21
17
- var value : String
22
+ extension Array : MyPrintable {
23
+ func print( ) {
24
+ Swift . print ( self , terminator: " " )
25
+ }
18
26
}
19
27
20
28
class Foo < T : MyPrintable > {
@@ -34,7 +42,81 @@ class Foo<T : MyPrintable> {
34
42
}
35
43
36
44
// CHECK: init 1 two
37
- var foo = Foo < PrintableValue > ( PrintableValue ( " 1 " ) , PrintableValue ( " two " ) )
38
- // CHECK: bar 3
39
- var c = PrintableValue ( " 3 " )
40
- foo. bar ( c)
45
+ // CHECK: bar [1]
46
+ var foo = Foo < Int > ( 1 , " two " )
47
+ foo. bar ( [ 1 ] )
48
+
49
+ struct OuterStruct < T : MyPrintable > {
50
+ let t : T
51
+
52
+ struct InnerStruct < U : MyPrintable > {
53
+ let u : U
54
+
55
+ func printBoth( t: T ) {
56
+ t. print ( )
57
+ print ( " " , terminator: " " )
58
+ u. print ( )
59
+ }
60
+
61
+ static func printBoth( t: T , u: U ) {
62
+ t. print ( )
63
+ print ( " " , terminator: " " )
64
+ u. print ( )
65
+ }
66
+
67
+ func printAllThree< V : MyPrintable > ( t: T , v: V ) {
68
+ printBoth ( t: t)
69
+ print ( " " , terminator: " " )
70
+ v. print ( )
71
+ }
72
+ }
73
+
74
+ class InnerClass < U : MyPrintable > {
75
+ let u : U
76
+
77
+ init ( u: U ) {
78
+ self . u = u
79
+ }
80
+
81
+ func printBoth( t: T ) {
82
+ t. print ( )
83
+ print ( " " , terminator: " " )
84
+ u. print ( )
85
+ }
86
+
87
+ static func printBoth( t: T , u: U ) {
88
+ t. print ( )
89
+ print ( " " , terminator: " " )
90
+ u. print ( )
91
+ }
92
+
93
+ func printAllThree< V : MyPrintable > ( t: T , v: V ) {
94
+ printBoth ( t: t)
95
+ print ( " " , terminator: " " )
96
+ v. print ( )
97
+ }
98
+ }
99
+ }
100
+
101
+ class SubClass < X : MyPrintable , Y : MyPrintable > : OuterStruct < Y > . InnerClass < X > {
102
+ override func printBoth( t: Y ) {
103
+ print ( " override " , terminator: " " )
104
+ super. printBoth ( t: t)
105
+ }
106
+
107
+ // FIXME: Does not work!
108
+ /* override func printAllThree<Z : MyPrintable>(t: Y, v: Z) {
109
+ print("super ", terminator: "")
110
+ super.printAllThree(t: t, v: v)
111
+ } */
112
+ }
113
+
114
+ // CHECK: 1 two
115
+ // CHECK: 1 two
116
+ // CHECK: 1 two [3]
117
+ OuterStruct < Int > . InnerStruct < String > ( u: " two " ) . printBoth ( t: 1 )
118
+ OuterStruct< Int> . InnerStruct < String > . printBoth( t: 1 , u: " two " )
119
+ OuterStruct < Int > . InnerStruct < String > ( u: " two " ) . printAllThree ( t: 1 , v: [ 3 ] )
120
+
121
+ // CHECK: override 1 two [3]
122
+ SubClass < String , Int > ( u: " two " ) . printAllThree ( t: 1 , v: [ 3 ] )
0 commit comments