]> Cypherpunks.ru repositories - gostls13.git/blob - test/used.go
Merge branch 'master' into dev.regabi
[gostls13.git] / test / used.go
1 // errorcheck
2
3 // Copyright 2020 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 p
8
9 import "unsafe"
10
11 const C = 1
12
13 var x, x1, x2 int
14 var b bool
15 var s string
16 var c chan int
17 var cp complex128
18 var slice []int
19 var array [2]int
20 var bytes []byte
21 var runes []rune
22 var r rune
23
24 func f0()            {}
25 func f1() int        { return 1 }
26 func f2() (int, int) { return 1, 1 }
27
28 type T struct{ X int }
29
30 func (T) M1() int { return 1 }
31 func (T) M0()     {}
32 func (T) M()      {}
33
34 var t T
35 var tp *T
36
37 type I interface{ M() }
38
39 var i I
40
41 var m map[int]int
42
43 func _() {
44         // Note: if the next line changes to x, the error silences the x+x etc below!
45         x1 // ERROR "x1 evaluated but not used"
46
47         nil                    // ERROR "nil evaluated but not used"
48         C                      // ERROR  "C evaluated but not used"
49         1                      // ERROR "1 evaluated but not used"
50         x + x                  // ERROR "x \+ x evaluated but not used"
51         x - x                  // ERROR "x - x evaluated but not used"
52         x | x                  // ERROR "x \| x evaluated but not used"
53         "a" + s                // ERROR ".a. \+ s evaluated but not used"
54         &x                     // ERROR "&x evaluated but not used"
55         b && b                 // ERROR "b && b evaluated but not used"
56         append(slice, 1)       // ERROR "append\(slice, 1\) evaluated but not used"
57         string(bytes)          // ERROR "string\(bytes\) evaluated but not used"
58         string(runes)          // ERROR "string\(runes\) evaluated but not used"
59         f0()                   // ok
60         f1()                   // ok
61         f2()                   // ok
62         _ = f0()               // ERROR "f0\(\) used as value"
63         _ = f1()               // ok
64         _, _ = f2()            // ok
65         _ = f2()               // ERROR "assignment mismatch: 1 variable but f2 returns 2 values"
66         T.M0                   // ERROR "T.M0 evaluated but not used"
67         t.M0                   // ERROR "t.M0 evaluated but not used"
68         cap                    // ERROR "use of builtin cap not in function call"
69         cap(slice)             // ERROR "cap\(slice\) evaluated but not used"
70         close(c)               // ok
71         _ = close(c)           // ERROR "close\(c\) used as value"
72         func() {}              // ERROR "func literal evaluated but not used"
73         X{}                    // ERROR "undefined: X"
74         map[string]int{}       // ERROR "map\[string\]int{} evaluated but not used"
75         struct{}{}             // ERROR "struct ?{}{} evaluated but not used"
76         [1]int{}               // ERROR "\[1\]int{} evaluated but not used"
77         []int{}                // ERROR "\[\]int{} evaluated but not used"
78         &struct{}{}            // ERROR "&struct ?{}{} evaluated but not used"
79         float32(x)             // ERROR "float32\(x\) evaluated but not used"
80         I(t)                   // ERROR "I\(t\) evaluated but not used"
81         int(x)                 // ERROR "int\(x\) evaluated but not used"
82         copy(slice, slice)     // ok
83         _ = copy(slice, slice) // ok
84         delete(m, 1)           // ok
85         _ = delete(m, 1)       // ERROR "delete\(m, 1\) used as value"
86         t.X                    // ERROR "t.X evaluated but not used"
87         tp.X                   // ERROR "tp.X evaluated but not used"
88         t.M                    // ERROR "t.M evaluated but not used"
89         I.M                    // ERROR "I.M evaluated but not used"
90         i.(T)                  // ERROR "i.\(T\) evaluated but not used"
91         x == x                 // ERROR "x == x evaluated but not used"
92         x != x                 // ERROR "x != x evaluated but not used"
93         x != x                 // ERROR "x != x evaluated but not used"
94         x < x                  // ERROR "x < x evaluated but not used"
95         x >= x                 // ERROR "x >= x evaluated but not used"
96         x > x                  // ERROR "x > x evaluated but not used"
97         *tp                    // ERROR "\*tp evaluated but not used"
98         slice[0]               // ERROR "slice\[0\] evaluated but not used"
99         m[1]                   // ERROR "m\[1\] evaluated but not used"
100         len(slice)             // ERROR "len\(slice\) evaluated but not used"
101         make(chan int)         // ERROR "make\(chan int\) evaluated but not used"
102         make(map[int]int)      // ERROR "make\(map\[int\]int\) evaluated but not used"
103         make([]int, 1)         // ERROR "make\(\[\]int, 1\) evaluated but not used"
104         x * x                  // ERROR "x \* x evaluated but not used"
105         x / x                  // ERROR "x / x evaluated but not used"
106         x % x                  // ERROR "x % x evaluated but not used"
107         x << x                 // ERROR "x << x evaluated but not used"
108         x >> x                 // ERROR "x >> x evaluated but not used"
109         x & x                  // ERROR "x & x evaluated but not used"
110         x &^ x                 // ERROR "x &\^ x evaluated but not used"
111         new(int)               // ERROR "new\(int\) evaluated but not used"
112         !b                     // ERROR "!b evaluated but not used"
113         ^x                     // ERROR "\^x evaluated but not used"
114         +x                     // ERROR "\+x evaluated but not used"
115         -x                     // ERROR "-x evaluated but not used"
116         b || b                 // ERROR "b \|\| b evaluated but not used"
117         panic(1)               // ok
118         _ = panic(1)           // ERROR "panic\(1\) used as value"
119         print(1)               // ok
120         _ = print(1)           // ERROR "print\(1\) used as value"
121         println(1)             // ok
122         _ = println(1)         // ERROR "println\(1\) used as value"
123         c <- 1                 // ok
124         slice[1:1]             // ERROR "slice\[1:1\] evaluated but not used"
125         array[1:1]             // ERROR "array\[1:1\] evaluated but not used"
126         s[1:1]                 // ERROR "s\[1:1\] evaluated but not used"
127         slice[1:1:1]           // ERROR "slice\[1:1:1\] evaluated but not used"
128         array[1:1:1]           // ERROR "array\[1:1:1\] evaluated but not used"
129         recover()              // ok
130         <-c                    // ok
131         string(r)              // ERROR "string\(r\) evaluated but not used"
132         iota                   // ERROR "undefined: iota"
133         real(cp)               // ERROR "real\(cp\) evaluated but not used"
134         imag(cp)               // ERROR "imag\(cp\) evaluated but not used"
135         complex(1, 2)          // ERROR "complex\(1, 2\) evaluated but not used"
136         unsafe.Alignof(t.X)    // ERROR "unsafe.Alignof\(t.X\) evaluated but not used"
137         unsafe.Offsetof(t.X)   // ERROR "unsafe.Offsetof\(t.X\) evaluated but not used"
138         unsafe.Sizeof(t)       // ERROR "unsafe.Sizeof\(t\) evaluated but not used"
139         _ = int                // ERROR "type int is not an expression"
140         (x)                    // ERROR "x evaluated but not used"
141         _ = new(x2)            // ERROR "x2 is not a type"
142         _ = new(1 + 1)         // ERROR "1 \+ 1 is not a type"
143 }