1
2
3
4
5
6
7 package stmt0
8
9 func assignments0() (int, int) {
10 var a, b, c int
11 var ch chan int
12 f0 := func() {}
13 f1 := func() int { return 1 }
14 f2 := func() (int, int) { return 1, 2 }
15 f3 := func() (int, int, int) { return 1, 2, 3 }
16
17 a, b, c = 1, 2, 3
18 a, b, c = 1 , 2
19 a, b, c = 1 , 2, 3, 4
20 _, _, _ = a, b, c
21
22 a = f0 ()
23 a = f1()
24 a = f2 ()
25 a, b = f2()
26 a, b, c = f2 ()
27 a, b, c = f3()
28 a, b = f3 ()
29
30 a, b, c = <- ch
31
32 return
33 return 1
34 return 1, 2
35 return 1, 2, 3
36 }
37
38 func assignments1() {
39 b, i, f, c, s := false, 1, 1.0, 1i, "foo"
40 b = i
41 i = f
42 f = c
43 c = s
44 s = b
45
46 v0, v1, v2 := 1 , 2, 3, 4
47 _, _, _ = v0, v1, v2
48
49 b = true
50
51 i += 1
52 i += "foo"
53
54 f -= 1
55 f /= 0
56 f = float32(0)/0
57 f -= "foo"
58
59 c *= 1
60 c /= 0
61
62 s += "bar"
63 s += 1
64
65 var u64 uint64
66 u64 += 1<<u64
67
68 undefined = 991
69
70
71 var (
72 _ int = nil
73 _ [10]int = nil
74 _ []byte = nil
75 _ struct{} = nil
76 _ func() = nil
77 _ map[int]string = nil
78 _ chan int = nil
79 )
80
81
82 _ = func() (int, bool) {
83 var m map[int]int
84 return m [0]
85 }
86
87 g := func(int, bool){}
88 var m map[int]int
89 g(m[0])
90
91
92 _ = nil
93 _ = 1 << 1000
94 (_) = 0
95 }
96
97 func assignments2() {
98 type mybool bool
99 var m map[string][]bool
100 var s []bool
101 var b bool
102 var d mybool
103 _ = s
104 _ = b
105 _ = d
106
107
108 s, b = m["foo"]
109 _, d = m["bar"]
110 m["foo"] = nil
111 m["foo"] = nil , false
112 _ = append(m["foo"])
113 _ = append(m["foo"], true)
114
115 var c chan int
116 _, b = <-c
117 _, d = <-c
118 <- c = 0
119 <-c = 0 , false
120
121 var x interface{}
122 _, b = x.(int)
123 x .(int) = 0
124 x.(int) = 0 , false
125
126 assignments2 () = nil
127 int = 0
128 }
129
130 func issue6487() {
131 type S struct{x int}
132 _ = &S {}.x
133 _ = &( S{}.x)
134 _ = (&S{}).x
135 S {}.x = 0
136 (&S{}).x = 0
137
138 type M map[string]S
139 var m M
140 m ["foo"].x = 0
141 _ = &( m["foo"].x)
142 _ = &m ["foo"].x
143 }
144
145 func issue6766a() {
146 a, a := 1, 2
147 _ = a
148 a, b, b := 1, 2, 3
149 _ = b
150 c, c , b := 1, 2, 3
151 _ = c
152 a, b := 1, 2
153 }
154
155 func shortVarDecls1() {
156 const c = 0
157 type d int
158 a, b, c , d := 1, "zwei", 3.0, 4
159 var _ int = a
160 var _ string = b
161 }
162
163 func incdecs() {
164 const c = 3.14
165 c ++
166 s := "foo"
167 s --
168 3.14 ++
169 var (
170 x int
171 y float32
172 z complex128
173 )
174 x++
175 y--
176 z++
177 }
178
179 func sends() {
180 var ch chan int
181 var rch <-chan int
182 var x int
183 x <- x
184 rch <- x
185 ch <- "foo"
186 ch <- x
187 }
188
189 func selects() {
190 select {}
191 var (
192 ch chan int
193 sc chan <- bool
194 )
195 select {
196 case <-ch:
197 case (<-ch):
198 case t := <-ch:
199 _ = t
200 case t := (<-ch):
201 _ = t
202 case t, ok := <-ch:
203 _, _ = t, ok
204 case t, ok := (<-ch):
205 _, _ = t, ok
206 case <-sc :
207 }
208 select {
209 default:
210 default :
211 }
212 select {
213 case a, b := <-ch:
214 _, b = a, b
215 case x :
216 case a := ch:
217 }
218
219
220
221 ch1 := make(chan int)
222 ch2 := make(chan int)
223 select {
224 case <-ch1:
225 var ch2 chan bool
226 case i := <-ch2:
227 print(i + 1)
228 }
229 }
230
231 func gos() {
232 go 1;
233 go int (0)
234 go ( gos())
235 go gos()
236 var c chan int
237 go close(c)
238 go len (c)
239 }
240
241 func defers() {
242 defer 1;
243 defer int (0)
244 defer ( defers())
245 defer defers()
246 var c chan int
247 defer close(c)
248 defer len (c)
249 }
250
251 func breaks() {
252 var x, y int
253
254 break
255 {
256 break
257 }
258 if x < y {
259 break
260 }
261
262 switch x {
263 case 0:
264 break
265 case 1:
266 if x == y {
267 break
268 }
269 default:
270 break
271 break
272 }
273
274 var z interface{}
275 switch z.(type) {
276 case int:
277 break
278 }
279
280 for {
281 break
282 }
283
284 var a []int
285 for _ = range a {
286 break
287 }
288
289 for {
290 if x == y {
291 break
292 }
293 }
294
295 var ch chan int
296 select {
297 case <-ch:
298 break
299 }
300
301 select {
302 case <-ch:
303 if x == y {
304 break
305 }
306 default:
307 break
308 }
309 }
310
311 func continues() {
312 var x, y int
313
314 continue
315 {
316 continue
317 }
318
319 if x < y {
320 continue
321 }
322
323 switch x {
324 case 0:
325 continue
326 }
327
328 var z interface{}
329 switch z.(type) {
330 case int:
331 continue
332 }
333
334 var ch chan int
335 select {
336 case <-ch:
337 continue
338 }
339
340 for i := 0; i < 10; i++ {
341 continue
342 if x < y {
343 continue
344 break
345 }
346 switch x {
347 case y:
348 continue
349 default:
350 break
351 }
352 select {
353 case <-ch:
354 continue
355 }
356 }
357
358 var a []int
359 for _ = range a {
360 continue
361 if x < y {
362 continue
363 break
364 }
365 switch x {
366 case y:
367 continue
368 default:
369 break
370 }
371 select {
372 case <-ch:
373 continue
374 }
375 }
376 }
377
378 func returns0() {
379 return
380 return 0
381 }
382
383 func returns1(x float64) (int, *float64) {
384 return 0, &x
385 return
386 return "foo" , x
387 return 0, &x, 1
388 }
389
390 func returns2() (a, b int) {
391 return
392 return 1, "foo"
393 return 1, 2, 3
394 {
395 type a int
396 return 1, 2
397 return
398 }
399 }
400
401 func returns3() (_ int) {
402 return
403 {
404 var _ int
405 return
406 }
407 }
408
409 func switches0() {
410 var x int
411
412 switch x {
413 }
414
415 switch x {
416 default:
417 default :
418 }
419
420 switch {
421 case 1 :
422 }
423
424 true := "false"
425 _ = true
426
427
428 switch {
429 case "false" :
430 }
431
432 switch int32(x) {
433 case 1, 2:
434 case x :
435 }
436
437 switch x {
438 case 1 << 100:
439 }
440
441 switch x {
442 case 1:
443 case 1 :
444 case ( 1):
445 case 2, 3, 4:
446 case 5, 1 :
447 }
448
449 switch uint64(x) {
450 case 1<<64 - 1:
451 case 1 <<64 - 1:
452 case 2, 3, 4:
453 case 5, 1 <<64 - 1:
454 }
455
456 var y32 float32
457 switch y32 {
458 case 1.1:
459 case 11/10:
460 case 11. /10:
461 case 2, 3.0, 4.1:
462 case 5.2, 1.10 :
463 }
464
465 var y64 float64
466 switch y64 {
467 case 1.1:
468 case 11/10:
469 case 11. /10:
470 case 2, 3.0, 4.1:
471 case 5.2, 1.10 :
472 }
473
474 var s string
475 switch s {
476 case "foo":
477 case "foo" :
478 case "f" + "oo":
479 case "abc", "def", "ghi":
480 case "jkl", "foo" :
481 }
482
483 type T int
484 type F float64
485 type S string
486 type B bool
487 var i interface{}
488 switch i {
489 case nil:
490 case nil:
491 case (*int)(nil):
492 case (*int)(nil):
493 case 1:
494 case byte(1):
495 case int (1):
496 case T(1):
497 case 1.0:
498 case F(1.0):
499 case F (1.0):
500 case "hello":
501 case S("hello"):
502 case S ("hello"):
503 case 1==1, B(false):
504 case false, B(2==2):
505 }
506
507
508 var a [3]int
509 switch a {
510 case [3]int{1, 2, 3}:
511 case [3]int{1, 2, 3}:
512 case [ 4]int{4, 5, 6}:
513 }
514
515
516 var c1, c2 chan int
517 switch c1 {
518 case nil:
519 case c1:
520 case c2:
521 case c1, c2:
522 }
523 }
524
525 func switches1() {
526 fallthrough
527
528 var x int
529 switch x {
530 case 0:
531 fallthrough
532 break
533 case 1:
534 fallthrough
535 case 2:
536 fallthrough; ; ;
537 case 3:
538 default:
539 fallthrough; ;
540 case 4:
541 fallthrough
542 }
543
544 var y interface{}
545 switch y.(type) {
546 case int:
547 fallthrough ; ; ;
548 default:
549 }
550
551 switch x {
552 case 0:
553 if x == 0 {
554 fallthrough
555 }
556 }
557
558 switch x {
559 case 0:
560 goto L1
561 L1: fallthrough; ;
562 case 1:
563 goto L2
564 goto L3
565 goto L4
566 L2: L3: L4: fallthrough
567 default:
568 }
569
570 switch x {
571 case 0:
572 goto L5
573 L5: fallthrough
574 default:
575 goto L6
576 goto L7
577 goto L8
578 L6: L7: L8: fallthrough
579 }
580
581 switch x {
582 case 0:
583 fallthrough; ;
584 case 1:
585 {
586 fallthrough
587 }
588 case 2:
589 fallthrough
590 case 3:
591 fallthrough
592 { }; ;
593 default:
594 fallthrough
595 }
596
597 switch x {
598 case 0:
599 {
600 fallthrough
601 }
602 }
603 }
604
605 func switches2() {
606
607 switch nil {
608 case 1, 2, "foo":
609 }
610
611
612 switch 1<<63-1 {
613 }
614 switch 1 << 63 {
615 }
616 var x int
617 switch 1.0 {
618 case 1.0, 2.0, x :
619 }
620 switch x {
621 case 1.0:
622 }
623
624
625 type B bool
626 var b B = true
627 switch x == x {
628 case b :
629 }
630 switch {
631 case b :
632 }
633 }
634
635 func issue11667() {
636 switch 9223372036854775808 {
637 }
638 switch 9223372036854775808 {
639 case 9223372036854775808:
640 }
641 var x int
642 switch x {
643 case 9223372036854775808 :
644 }
645 var y float64
646 switch y {
647 case 9223372036854775808:
648 }
649 }
650
651 func issue11687() {
652 f := func() (_, _ int) { return }
653 switch f () {
654 }
655 var x int
656 switch f () {
657 case x:
658 }
659 switch x {
660 case f ():
661 }
662 }
663
664 type I interface {
665 m()
666 }
667
668 type I2 interface {
669 m(int)
670 }
671
672 type T struct{}
673 type T1 struct{}
674 type T2 struct{}
675
676 func (T) m() {}
677 func (T2) m(int) {}
678
679 func typeswitches() {
680 var i int
681 var x interface{}
682
683 switch x.(type) {}
684 switch (x .(type)) {}
685
686 switch x.(type) {
687 default:
688 default :
689 }
690
691 switch x := x.(type) {}
692 switch _ := x.(type) {}
693
694 switch x := x.(type) {
695 case int:
696 var y int = x
697 _ = y
698 }
699
700 switch x := i .(type) {}
701
702 switch t := x.(type) {
703 case nil:
704 var v bool = t
705 _ = v
706 case int:
707 var v int = t
708 _ = v
709 case float32, complex64:
710 var v float32 = t
711 _ = v
712 default:
713 var v float32 = t
714 _ = v
715 }
716
717 var t I
718 switch t.(type) {
719 case T:
720 case T1 :
721 case T2 :
722 case I2 :
723 }
724
725
726 {
727 x := 1
728 v := 2
729 switch v .(type) {
730 case int:
731 println(x)
732 println(x / 0 )
733 case 1 :
734 }
735 }
736 }
737
738
739
740 func typeswitch0() {
741 switch y := interface{}(nil).(type) {
742 case int:
743 func() int { return y + 0 }()
744 case float32:
745 func() float32 { return y }()
746 }
747 }
748
749
750
751 func typeswitch1() {
752 var t I
753 switch t := t; t := t.(type) {
754 case nil:
755 var _ I = t
756 case T:
757 var _ T = t
758 default:
759 var _ I = t
760 }
761 }
762
763
764 type A interface { a() }
765 type B interface { b() }
766 type C interface { a(int) }
767
768 func typeswitch2() {
769 switch A(nil).(type) {
770 case A:
771 case B:
772 case C :
773 }
774 }
775
776 func typeswitch3(x interface{}) {
777 switch x.(type) {
778 case int:
779 case float64:
780 case int :
781 }
782
783 switch x.(type) {
784 case nil:
785 case int:
786 case nil , nil :
787 }
788
789 type F func(int)
790 switch x.(type) {
791 case nil:
792 case int, func(int):
793 case float32, func (x int):
794 case F:
795 }
796 }
797
798 func fors1() {
799 for {}
800 var i string
801 _ = i
802 for i := 0; i < 10; i++ {}
803 for i := 0; i < 10; j := 0 {}
804 }
805
806 func rangeloops1() {
807 var (
808 a [10]float32
809 b []string
810 p *[10]complex128
811 pp **[10]complex128
812 s string
813 m map[int]bool
814 c chan int
815 sc chan<- int
816 rc <-chan int
817 xs struct{}
818 )
819
820 for range xs {}
821 for _ = range xs {}
822 for i := range xs { _ = i }
823
824 for range a {}
825 for i := range a {
826 var ii int
827 ii = i
828 _ = ii
829 }
830 for i, x := range a {
831 var ii int
832 ii = i
833 _ = ii
834 var xx float64
835 xx = x
836 _ = xx
837 }
838 var ii int
839 var xx float32
840 for ii, xx = range a {}
841 _, _ = ii, xx
842
843 for range b {}
844 for i := range b {
845 var ii int
846 ii = i
847 _ = ii
848 }
849 for i, x := range b {
850 var ii int
851 ii = i
852 _ = ii
853 var xx string
854 xx = x
855 _ = xx
856 }
857
858 for range s {}
859 for i := range s {
860 var ii int
861 ii = i
862 _ = ii
863 }
864 for i, x := range s {
865 var ii int
866 ii = i
867 _ = ii
868 var xx rune
869 xx = x
870 _ = xx
871 }
872
873 for range p {}
874 for _, x := range p {
875 var xx complex128
876 xx = x
877 _ = xx
878 }
879
880 for range pp {}
881 for _, x := range pp {}
882
883 for range m {}
884 for k := range m {
885 var kk int32
886 kk = k
887 _ = kk
888 }
889 for k, v := range m {
890 var kk int
891 kk = k
892 _ = kk
893 if v {}
894 }
895
896 for range c {}
897 for _, _ = range c {}
898 for e := range c {
899 var ee int
900 ee = e
901 _ = ee
902 }
903 for _ = range sc {}
904 for _ = range rc {}
905
906
907 const cs = "foo"
908 for range cs {}
909 for range "" {}
910 for i, x := range cs { _, _ = i, x }
911 for i, x := range "" {
912 var ii int
913 ii = i
914 _ = ii
915 var xx rune
916 xx = x
917 _ = xx
918 }
919 }
920
921 func rangeloops2() {
922 type I int
923 type R rune
924
925 var a [10]int
926 var i I
927 _ = i
928 for i = range a {}
929 for i = range &a {}
930 for i = range a[:] {}
931
932 var s string
933 var r R
934 _ = r
935 for i = range s {}
936 for i = range "foo" {}
937 for _, r = range s {}
938 for _, r = range "foo" {}
939 }
940
941 func issue6766b() {
942 for _ := range "" {}
943 for a, a := range "" { _ = a }
944 var a int
945 _ = a
946 for a, a := range []int{1, 2, 3} { _ = a }
947 }
948
949
950
951
952 func issue10148() {
953 for y := range "" {
954 _ = "" + 1
955 }
956 for range 1.5 {
957 _ = "" + 1
958 }
959 for y := range 1.5 {
960 _ = "" + 1
961 }
962 }
963
964 func labels0() {
965 goto L0
966 goto L1
967 L0:
968 L1:
969 L1 :
970 if true {
971 goto L2
972 L2:
973 L0 :
974 }
975 _ = func() {
976 goto L0
977 goto L1
978 goto L2
979 L0:
980 L1:
981 L2:
982 }
983 }
984
985 func expression_statements(ch chan int) {
986 expression_statements(ch)
987 <-ch
988 println()
989
990 0
991 1 +2
992 cap (ch)
993 println
994 }
995
View as plain text