1
2
3
4
5 package untyped_lit
6
7
8
9 type (
10 _Basic = int
11 _Array = [10]int
12 _Slice = []int
13 _Struct = struct{ f int }
14 _Pointer = *int
15 _PointerS = *_Struct
16 _Func = func(int) string
17 _Interface = interface{ m() int }
18 _Map = map[string]int
19 _Chan = chan int
20
21 Basic _Basic
22 Array _Array
23 Slice _Slice
24 Struct _Struct
25 Pointer _Pointer
26 PointerS _PointerS
27 Func _Func
28 Interface _Interface
29 Map _Map
30 Chan _Chan
31
32 GArray[E any] [10]E
33 GSlice[E any] []E
34 GStruct[E any] struct{ f E }
35 GMap[K comparable, V any] map[K]V
36 )
37
38
39
40
41
42 func _() {
43
44 var (
45 _ _Basic = { }
46 _ _Array = {}
47 _ _Array = {1, 2, 3}
48 _ _Slice = {}
49 _ _Slice = {1, 2, 3}
50 _ _Struct = {}
51 _ _Struct = {1}
52 _ _Struct = {f: 1}
53 _ _Pointer = { }
54 _ _PointerS = {}
55 _ _PointerS = {1}
56 _ _PointerS = {f: 1}
57 _ _Func = { }
58 _ _Interface = { }
59 _ any = { }
60 _ _Map = {}
61 _ _Map = {"a": 1}
62 _ _Chan = { }
63 )
64
65
66 var (
67 _ Basic = { }
68 _ Array = {}
69 _ Array = {1, 2, 3}
70 _ Slice = {}
71 _ Slice = {1, 2, 3}
72 _ Struct = {}
73 _ Struct = {1}
74 _ Struct = {f: 1}
75 _ Pointer = { }
76 _ PointerS = {}
77 _ PointerS = {1}
78 _ PointerS = {f: 1}
79 _ Func = { }
80 _ Interface = { }
81 _ Map = {}
82 _ Map = {"a": 1}
83 _ Chan = { }
84 )
85
86
87 var (
88 _ GArray[int] = {}
89 _ GArray[int] = {1, 2, 3}
90 _ GSlice[int] = {}
91 _ GSlice[int] = {1, 2, 3}
92 _ GStruct[int] = {}
93 _ GStruct[int] = {1}
94 _ GStruct[int] = {f: 1}
95 _ GMap[string, int] = {}
96 _ GMap[string, int] = {"a": 1}
97 )
98 }
99
100
101 func _[
102 P0 any,
103 PB ~int,
104 PA ~[10]int,
105 PA2 [10]int | Array,
106 PA_bad [10]int | [20]int,
107 PL ~[]int,
108 PL2 []int | Slice,
109 PLA_bad []int | [10]int,
110 PS ~struct{ f int },
111 PS2 struct{ f int } | Struct,
112 PS_bad struct{ f int } | struct{ g int },
113 PP ~*int,
114 PPS ~*_Struct,
115 PF ~func(int) string,
116 PI Interface,
117 PM ~map[string]int,
118 PM2 map[string]int | Map,
119 PC ~chan int,
120 ]() {
121 var (
122 _ P0 = { }
123 _ PB = { }
124 _ PA = {}
125 _ PA = {1, 2, 3}
126 _ PA2 = {0: 1, 9: 2}
127 _ PA_bad = { }
128 _ PL = {}
129 _ PL = {1, 2, 3}
130 _ PL2 = {0: 1, 2: 3}
131 _ PLA_bad = { }
132 _ PS = {}
133 _ PS = {1}
134 _ PS = {f: 1}
135 _ PS2 = {f: 1}
136 _ PS_bad = { }
137 _ PP = { }
138 _ PPS = {}
139 _ PPS = {f: 1}
140 _ PF = { }
141 _ PI = { }
142 _ PM = {}
143 _ PM = {"a": 1}
144 _ PM2 = {"a": 1}
145 _ PC = { }
146 )
147 }
148
149
150
151
152 func _() {
153
154 type Inner struct {
155 a, b int
156 }
157 type Outer struct {
158 Inner
159 x int
160 s string
161 }
162
163 var (
164 _ Outer = {}
165 _ Outer = {{1, 2}, 3, "foo"}
166 _ Outer = {Inner: {1, 2}, x: 3, s: "foo"}
167 _ Outer = {a: 1, b: 2, x: 3, s: "foo"}
168 _ Outer = {{1, 2}, 3}
169 _ Outer = {{1, 2}, 3, "foo", 4 }
170 _ Outer = {x: 3, "foo" }
171 _ Outer = {{1, 2}, x : 3, "foo"}
172 _ Outer = {z : 1}
173 _ Outer = {x: 1, x : 2}
174 _ Outer = {Inner: {1, 2}, a : 1}
175 _ Outer = {x: "foo" }
176 )
177
178
179 var (
180 _ [3]int = {}
181 _ [3]int = {1, 2, 3}
182 _ [3]int = {0: 1, 2: 3}
183 _ [3]int = {1: 2, 3}
184 _ [3]int = {1, 2, 3, 4 }
185 _ [3]int = {3 : 1}
186 _ [3]int = {- 1: 1}
187 _ [3]int = {"a" : 1}
188 _ [3]int = {0: 1, 0 : 2}
189 _ [3]int = {1: 1, 0: 2, 3 }
190 _ [3]int = {"a" }
191 )
192
193
194 var (
195 _ []int = {}
196 _ []int = {1, 2, 3}
197 _ []int = {0: 1, 10: 2}
198 _ []int = {- 1: 1}
199 _ []int = {"a" : 1}
200 _ []int = {0: 1, 0 : 2}
201 _ []int = {"a" }
202 )
203
204
205 k := "key"
206 var (
207 _ map[string]int = {}
208 _ map[string]int = {"a": 1, "b": 2}
209 _ map[string]int = {k: 1}
210 _ map[string]int = {1 }
211 _ map[string]int = {"a": 1, "a" : 2}
212 _ map[string]int = {1 : 1}
213 _ map[string]int = {"a": "b" }
214 )
215 }
216
217
218
219
220
221 func _() {
222 var _ = { }
223 var _ = { 1, 2}
224 var _ = { f: 1}
225
226 var s Struct = {1}
227 var s1, l1 = Struct{1}, Slice{1, 2}
228 var s2, s3 Struct = {1}, {f: 2}
229 _, _, _, _ = s, s1, s2, s3
230 _ = l1
231
232 x := { }
233 _ = x
234
235
236 var r Struct
237 r, y := {1}, 42
238 _, _ = r, y
239 }
240
241
242 func _() {
243 const _ Struct = {}
244 const _ int = { }
245 const _ = { }
246 }
247
248
249 func _() {
250 _ = { }
251
252 var (
253 s Struct
254 a Array
255 l Slice
256 m Map
257 p PointerS
258 box struct{ s Struct }
259 arr [1]Struct
260 ptr *Struct
261 mp map[string]Struct
262 )
263
264 s = {}
265 s = {1}
266 s = {f: 1}
267 a = {1, 2, 3, 9: 10}
268 l = {1, 2, 3}
269 m = {"a": 1, "b": 2}
270 p = {f: 1}
271
272
273 s, l, m = {1}, {1, 2}, {"a": 1}
274
275
276 box.s = {1}
277 arr[0] = {f: 2}
278 *ptr = {3}
279 mp["k"] = {4}
280
281 _, _, _, _, _, _, _ = s, a, l, m, p, box, arr
282 }
283
284
285 func _() Struct {
286 return {}
287 return {1}
288 return {f: 1}
289 }
290
291 func _() (Struct, Slice, Map) {
292 return {1}, {1, 2, 3}, {"a": 1}
293 }
294
295 func _() (s Struct, a Array, l Slice, m Map) {
296 return {f: 1}, {0: 1}, {1, 2}, {"a": 1}
297 }
298
299
300 type Recv struct{ x int }
301
302 func (Recv) m(s Struct, rest ...Slice) {}
303
304 func _() {
305 f := func(s Struct, a Array, l Slice, m Map) {}
306 f({}, {}, {}, {})
307 f({1}, {1, 2}, {3, 4}, {"a": 5})
308
309 fv := func(x int, rest ...Struct) {}
310 fv(0)
311 fv(0, {})
312 fv(0, {1}, {f: 2})
313
314 var r Recv
315 r.m({1}, {1, 2}, {3, 4})
316 Recv.m({1}, {2}, {1, 2}, {3, 4})
317 }
318
319 func fg[P any](x P) {}
320 func fgc[P ~struct{ f int }](x P) {}
321
322 func _() {
323 fg[Struct]({})
324 fg[Struct]({1})
325 fg[Slice]({1, 2, 3})
326 fg[Map]({"a": 1})
327
328 fgc[Struct]({1})
329 fgc({f: 1})
330 }
331
332
333 func _() {
334 type Nested struct {
335 s Struct
336 a [2]Struct
337 l []Struct
338 m map[Struct]Slice
339 p *Struct
340 }
341
342
343 _ = Nested{
344 s: {1},
345 a: {{1}, {f: 2}},
346 l: {{1}, {f: 2}},
347 m: {{1}: {1, 2}, {f: 2}: {}},
348 p: {f: 3},
349 }
350 _ = Nested{
351 {1},
352 {{1}, {f: 2}},
353 {{1}, {f: 2}},
354 {{1}: {1, 2}, {f: 2}: {}},
355 {f: 3},
356 }
357
358
359 var _ Nested = {
360 s: {1},
361 a: {{1}, {f: 2}},
362 l: {{1}, {f: 2}},
363 m: {{1}: {1, 2}, {f: 2}: {}},
364 p: {f: 3},
365 }
366 var _ Nested = {
367 {1},
368 {{1}, {f: 2}},
369 {{1}, {f: 2}},
370 {{1}: {1, 2}, {f: 2}: {}},
371 {f: 3},
372 }
373
374
375 _ = [...]Struct{{}, {1}, {f: 2}}
376 _ = [...]*Struct{{}, {1}, {f: 2}}
377
378
379 type FuncHolder struct {
380 fn func(int)
381 }
382 var _ FuncHolder = {fg}
383 var _ FuncHolder = {fn: fg}
384 }
385
386
387 func _[M ~map[Struct]Slice](gm M) {
388 var m map[Struct]Slice
389 _ = m[{}]
390 _ = m[{1}]
391 _ = m[{f: 1}]
392 v, ok := m[{f: 1}]
393 _, _ = v, ok
394 m[{1}] = {1, 2, 3}
395
396 var counts map[Struct]int
397 counts[{1}]++
398 counts[{f: 2}] += 10
399
400 _ = gm[{}]
401 gm[{1}] = {1, 2, 3}
402 }
403
404
405 func _[C ~chan Struct](gch C) {
406 var ch chan Struct
407 var sch chan<- Struct
408 ch <- {}
409 ch <- {1}
410 sch <- {f: 1}
411 gch <- {1}
412
413 select {
414 case ch <- {1}:
415 case sch <- {f: 2}:
416 default:
417 }
418 }
419
420
421 func _[P ~struct{ f int }]() {
422 _ = _Array({1, 2, 3})
423 _ = _Slice({1, 2, 3})
424 _ = _Struct({1})
425 _ = _Struct({f: 1})
426 _ = _PointerS({f: 1})
427 _ = _Map({"a": 1})
428
429 _ = Array({1, 2, 3})
430 _ = Slice({1, 2, 3})
431 _ = Struct({1})
432 _ = Struct({f: 1})
433 _ = PointerS({f: 1})
434 _ = Map({"a": 1})
435
436 _ = ([3]int)({1, 2, 3})
437 _ = ([]int)({1, 2, 3})
438 _ = (struct{ f int })({f: 1})
439 _ = (*struct{ f int })({f: 1})
440 _ = (map[string]int)({"a": 1})
441
442 _ = P({})
443 _ = P({1})
444 _ = P({f: 1})
445
446
447 _ = Struct({f: 1}).f
448 _ = Slice({1, 2, 3})[0]
449 _ = Slice({1, 2, 3})[1:3]
450 _ = Map({"a": 1})["a"]
451 }
452
453
454 func _() {
455 var (
456 s Struct
457 sl []Struct
458 l Slice
459 m map[Struct]int
460 )
461
462
463 var _ Struct = ({ 1})
464
465
466 var _ *Struct = &{ 1}
467
468
469 fv := func(x int, rest ...int) {}
470 fv(0, { 1, 2, 3}...)
471
472
473
474 _ = s == { 1}
475 _ = { 1} == s
476
477
478
479 switch s {
480 case { 1}:
481 }
482
483
484
485 _ = append(sl, { 1})
486 _ = copy(l, { 1, 2, 3})
487 delete(m, { 1})
488
489
490 _ = new({ })
491 _ = len({ })
492 _ = cap({ })
493 clear({ })
494 panic({ })
495 print({ })
496 println({ })
497 }
498
View as plain text