1
2
3
4
5
6
7 package p
8
9 import "io"
10 import "context"
11
12 func eql[T comparable](x, y T) bool {
13 return x == y
14 }
15
16 func _[X comparable, Y interface{comparable; m()}]() {
17 var x X
18 var y Y
19 eql(x, y )
20 eql(x, x)
21 eql(y, y)
22 eql(y, nil )
23 eql[io.Reader](nil, nil)
24 }
25
26
27
28 type C[T any] interface {
29 m()
30 }
31
32
33 func _[T C[T]](x *T) {
34 x.m ()
35 }
36
37
38 func _[T interface{ m() }](x *T) {
39 x.m ()
40 }
41
42 func f2[_ interface{ m1(); m2() }]() {}
43
44 type T struct{}
45 func (T) m1()
46 func (*T) m2()
47
48 func _() {
49 f2[T ]()
50 f2[*T]()
51 }
52
53
54
55
56 type T1[P interface{~uint}] struct{}
57
58 func _[P any]() {
59 _ = T1[P ]{}
60 }
61
62
63 type Unsigned interface {
64 ~uint
65 }
66
67 type T2[U Unsigned] struct {
68 s U
69 }
70
71 func (u T2[U]) Add1() U {
72 return u.s + 1
73 }
74
75 func NewT2[U any]() T2[U ] {
76 return T2[U ]{}
77 }
78
79 func _() {
80 u := NewT2[string]()
81 _ = u.Add1()
82 }
83
84
85
86
87 type Elem[T any] struct {
88 next *Elem[T]
89 list *List[T]
90 }
91
92 type List[T any] struct {
93 root Elem[T]
94 }
95
96 func (l *List[T]) Init() {
97 l.root.next = &l.root
98 }
99
100
101 type Element2[TElem any] struct {
102 next, prev *Element2[TElem]
103 list *List2[TElem]
104 Value TElem
105 }
106
107 type List2[TElem any] struct {
108 root Element2[TElem]
109 len int
110 }
111
112 func (l *List2[TElem]) Init() *List2[TElem] {
113 l.root.next = &l.root
114 l.root.prev = &l.root
115 l.len = 0
116 return l
117 }
118
119
120 type A[P any] struct { _ *A[P] }
121
122 type AB[P any] struct { _ *BA[P] }
123 type BA[P any] struct { _ *AB[P] }
124
125
126
127 type Element3[TElem any] struct {
128 next, prev *Element3[TElem]
129 list *List3[TElem]
130 Value TElem
131 }
132
133 func (e *Element3[TElem]) Next() *Element3[TElem] {
134 if p := e.next; e.list != nil && p != &e.list.root {
135 return p
136 }
137 return nil
138 }
139
140 type List3[TElem any] struct {
141 root Element3[TElem]
142 len int
143 }
144
145
146 type inf1[T any] struct{ _ inf1 [T] }
147 type inf2[T any] struct{ inf2 [T] }
148
149
150
151
152
153
154
155 func convert[T1, T2 interface{~int | ~uint | ~float32}](v T1) T2 {
156 return T2(v)
157 }
158
159 func _() {
160 convert[int, uint](5)
161 }
162
163
164
165
166
167 func issue39623[T interface{~int | ~string}](x, y T) T {
168 return x + y
169 }
170
171
172 func Sum[T interface{~int | ~string}](s []T) (sum T) {
173 for _, v := range s {
174 sum += v
175 }
176 return
177 }
178
179
180
181 func _[T interface{}, PT interface{~*T}] (x T) PT {
182 return &x
183 }
184
185
186 func at[T interface{ ~[]E }, E interface{}](x T, i int) E {
187 return x[i]
188 }
189
190
191 func _[T interface{~int}](x T) {
192 type myint int
193 var _ int = int(x)
194 var _ T = 42
195 var _ T = T(myint(42))
196 }
197
198
199
200 func _[T interface { ~[10]int }](x T) {
201 _ = x[9]
202 _ = x[20 ]
203 }
204
205
206 func _[T interface{ ~*int }](p T) int {
207 return *p
208 }
209
210
211 func _[T interface{ ~chan int }](ch T) int {
212 ch <- 0
213 return <- ch
214 }
215
216
217 func _[T interface{ ~func() }](f T) {
218 f()
219 go f()
220 }
221
222 type F1 func()
223 type F2 func()
224 func _[T interface{ func()|F1|F2 }](f T) {
225 f()
226 go f()
227 }
228
229
230
231
232
233
234
235
236 type sliceOf[E any] interface{ ~[]E }
237
238 func append[T interface{}, S sliceOf[T], T2 interface{}](s S, t ...T2) S { panic(0) }
239
240 var f func()
241 var cancelSlice []context.CancelFunc
242 var _ = append[context.CancelFunc, []context.CancelFunc, context.CancelFunc](cancelSlice, f)
243
244
245
246 func g[T any](T) T { panic(0) }
247
248 var _ = g[int]
249 var _ = g[nil ]
250 var _ = g(0)
251
View as plain text