]> Cypherpunks.ru repositories - gostls13.git/blob - test/blank.go
write-only variable _
[gostls13.git] / test / blank.go
1 // $G $D/$F.go && $L $F.$A && ./$A.out
2
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package main
8
9 var call string
10
11 type T struct {
12         _, _, _ int;
13 }
14
15 const (
16         c0 = iota;
17         _;
18         _;
19         _;
20         c4;
21 )
22
23 var ints = []string {
24         "1",
25         "2",
26         "3"
27 }
28
29 func f() (int, int) {
30         call += "f";
31         return 1,2
32 }
33
34 func g() (float, float) {
35         call += "g";
36         return 3,4
37 }
38
39 func h(_ int, _ float) {
40 }
41
42 func i() int {
43         call += "i";
44         return 23;
45 }
46
47 func main()
48 {
49         _, _ = f();
50         a, _ := f();
51         if a != 1 {panic(a)}
52         b, _ := g();
53         if b != 3 {panic(b)}
54         _, a = f();
55         if a != 2 {panic(a)}
56         _, b = g();
57         if b != 4 {panic(b)}
58         _ = i();
59         if call != "ffgfgi" {panic(call)}
60         if c4 != 4 {panic(c4)}
61
62         out := "";
63         for _, s := range ints {
64                 out += s;
65         }
66         if out != "123" {panic(out)}
67
68         sum := 0;
69         for s, _ := range ints {
70                 sum += s;
71         }
72         if sum != 3 {panic(sum)}
73
74         h(a,b);
75 }
76
77 // useless but legal
78 var _ int = 1;
79 var _ = 2;
80 var _, _ = 3, 4;
81 const _ = 3;
82 const _, _ = 4, 5;
83 type _ int;
84 func _() {
85         panic("oops")
86 }
87
88 func ff() {
89         var _ int = 1;
90 }