| 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 .* not used" |
| 46 |
|
| 47 |
nil // ERROR "nil .* not used" |
| 48 |
C // ERROR "C .* not used" |
| 49 |
1 // ERROR "1 .* not used" |
| 50 |
x + x // ERROR "x \+ x .* not used" |
| 51 |
x - x // ERROR "x - x .* not used" |
| 52 |
x | x // ERROR "x \| x .* not used" |
| 53 |
"a" + s // ERROR ".a. \+ s .* not used" |
| 54 |
&x // ERROR "&x .* not used" |
| 55 |
b && b // ERROR "b && b .* not used" |
| 56 |
append(slice, 1) // ERROR "append\(slice, 1\) .* not used" |
| 57 |
string(bytes) // ERROR "string\(bytes\) .* not used" |
| 58 |
string(runes) // ERROR "string\(runes\) .* 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|cannot assign" |
| 66 |
_ = f1(), 0 // ERROR "assignment mismatch: 1 variable but 2 values|cannot assign" |
| 67 |
T.M0 // ERROR "T.M0 .* not used" |
| 68 |
t.M0 // ERROR "t.M0 .* not used" |
| 69 |
cap // ERROR "use of builtin cap not in function call|must be called" |
| 70 |
cap(slice) // ERROR "cap\(slice\) .* not used" |
| 71 |
close(c) // ok |
| 72 |
_ = close(c) // ERROR "close\(c\) .*used as value" |
| 73 |
func() {} // ERROR "func literal .* not used|is not used" |
| 74 |
X{} // ERROR "undefined: X" |
| 75 |
map[string]int{} // ERROR "map\[string\]int{} .* not used" |
| 76 |
struct{}{} // ERROR "struct ?{}{} .* not used" |
| 77 |
[1]int{} // ERROR "\[1\]int{} .* not used" |
| 78 |
[]int{} // ERROR "\[\]int{} .* not used" |
| 79 |
&struct{}{} // ERROR "&struct ?{}{} .* not used" |
| 80 |
float32(x) // ERROR "float32\(x\) .* not used" |
| 81 |
I(t) // ERROR "I\(t\) .* not used" |
| 82 |
int(x) // ERROR "int\(x\) .* not used" |
| 83 |
copy(slice, slice) // ok |
| 84 |
_ = copy(slice, slice) // ok |
| 85 |
delete(m, 1) // ok |
| 86 |
_ = delete(m, 1) // ERROR "delete\(m, 1\) .*used as value" |
| 87 |
t.X // ERROR "t.X .* not used" |
| 88 |
tp.X // ERROR "tp.X .* not used" |
| 89 |
t.M // ERROR "t.M .* not used" |
| 90 |
I.M // ERROR "I.M .* not used" |
| 91 |
i.(T) // ERROR "i.\(T\) .* not used" |
| 92 |
x == x // ERROR "x == x .* not used" |
| 93 |
x != x // ERROR "x != x .* not used" |
| 94 |
x != x // ERROR "x != x .* not used" |
| 95 |
x < x // ERROR "x < x .* not used" |
| 96 |
x >= x // ERROR "x >= x .* not used" |
| 97 |
x > x // ERROR "x > x .* not used" |
| 98 |
*tp // ERROR "\*tp .* not used" |
| 99 |
slice[0] // ERROR "slice\[0\] .* not used" |
| 100 |
m[1] // ERROR "m\[1\] .* not used" |
| 101 |
len(slice) // ERROR "len\(slice\) .* not used" |
| 102 |
make(chan int) // ERROR "make\(chan int\) .* not used" |
| 103 |
make(map[int]int) // ERROR "make\(map\[int\]int\) .* not used" |
| 104 |
make([]int, 1) // ERROR "make\(\[\]int, 1\) .* not used" |
| 105 |
x * x // ERROR "x \* x .* not used" |
| 106 |
x / x // ERROR "x / x .* not used" |
| 107 |
x % x // ERROR "x % x .* not used" |
| 108 |
x << x // ERROR "x << x .* not used" |
| 109 |
x >> x // ERROR "x >> x .* not used" |
| 110 |
x & x // ERROR "x & x .* not used" |
| 111 |
x &^ x // ERROR "x &\^ x .* not used" |
| 112 |
new(int) // ERROR "new\(int\) .* not used" |
| 113 |
!b // ERROR "!b .* not used" |
| 114 |
^x // ERROR "\^x .* not used" |
| 115 |
+x // ERROR "\+x .* not used" |
| 116 |
-x // ERROR "-x .* not used" |
| 117 |
b || b // ERROR "b \|\| b .* not used" |
| 118 |
panic(1) // ok |
| 119 |
_ = panic(1) // ERROR "panic\(1\) .*used as value" |
| 120 |
print(1) // ok |
| 121 |
_ = print(1) // ERROR "print\(1\) .*used as value" |
| 122 |
println(1) // ok |
| 123 |
_ = println(1) // ERROR "println\(1\) .*used as value" |
| 124 |
c <- 1 // ok |
| 125 |
slice[1:1] // ERROR "slice\[1:1\] .* not used" |
| 126 |
array[1:1] // ERROR "array\[1:1\] .* not used" |
| 127 |
s[1:1] // ERROR "s\[1:1\] .* not used" |
| 128 |
slice[1:1:1] // ERROR "slice\[1:1:1\] .* not used" |
| 129 |
array[1:1:1] // ERROR "array\[1:1:1\] .* not used" |
| 130 |
recover() // ok |
| 131 |
<-c // ok |
| 132 |
string(r) // ERROR "string\(r\) .* not used" |
| 133 |
iota // ERROR "undefined: iota|cannot use iota" |
| 134 |
real(cp) // ERROR "real\(cp\) .* not used" |
| 135 |
imag(cp) // ERROR "imag\(cp\) .* not used" |
| 136 |
complex(1, 2) // ERROR "complex\(1, 2\) .* not used" |
| 137 |
unsafe.Alignof(t.X) // ERROR "unsafe.Alignof\(t.X\) .* not used" |
| 138 |
unsafe.Offsetof(t.X) // ERROR "unsafe.Offsetof\(t.X\) .* not used" |
| 139 |
unsafe.Sizeof(t) // ERROR "unsafe.Sizeof\(t\) .* not used" |
| 140 |
_ = int // ERROR "type int is not an expression|not an expression" |
| 141 |
(x) // ERROR "x .* not used|not used" |
| 142 |
_ = new(len) // ERROR "len.*must be called" |
| 143 |
_ = new(1 + 1) // ok |
| 144 |
} |