2020-12-04 10:40:39 -07:00
|
|
|
// errorcheck
|
|
|
|
|
|
|
|
// Copyright 2020 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package p
|
|
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
|
|
|
const C = 1
|
|
|
|
|
2020-12-04 09:37:54 -07:00
|
|
|
var x, x1, x2 int
|
2020-12-04 10:40:39 -07:00
|
|
|
var b bool
|
|
|
|
var s string
|
|
|
|
var c chan int
|
|
|
|
var cp complex128
|
|
|
|
var slice []int
|
|
|
|
var array [2]int
|
|
|
|
var bytes []byte
|
|
|
|
var runes []rune
|
|
|
|
var r rune
|
|
|
|
|
|
|
|
func f0() {}
|
|
|
|
func f1() int { return 1 }
|
|
|
|
func f2() (int, int) { return 1, 1 }
|
|
|
|
|
|
|
|
type T struct{ X int }
|
|
|
|
|
|
|
|
func (T) M1() int { return 1 }
|
|
|
|
func (T) M0() {}
|
|
|
|
func (T) M() {}
|
|
|
|
|
|
|
|
var t T
|
|
|
|
var tp *T
|
|
|
|
|
|
|
|
type I interface{ M() }
|
|
|
|
|
|
|
|
var i I
|
|
|
|
|
|
|
|
var m map[int]int
|
|
|
|
|
|
|
|
func _() {
|
|
|
|
// Note: if the next line changes to x, the error silences the x+x etc below!
|
2020-12-14 12:53:55 -07:00
|
|
|
x1 // ERROR "x1 .* not used"
|
2020-12-04 10:40:39 -07:00
|
|
|
|
2020-12-14 12:53:55 -07:00
|
|
|
nil // ERROR "nil .* not used"
|
|
|
|
C // ERROR "C .* not used"
|
|
|
|
1 // ERROR "1 .* not used"
|
|
|
|
x + x // ERROR "x \+ x .* not used"
|
|
|
|
x - x // ERROR "x - x .* not used"
|
|
|
|
x | x // ERROR "x \| x .* not used"
|
|
|
|
"a" + s // ERROR ".a. \+ s .* not used"
|
|
|
|
&x // ERROR "&x .* not used"
|
|
|
|
b && b // ERROR "b && b .* not used"
|
|
|
|
append(slice, 1) // ERROR "append\(slice, 1\) .* not used"
|
|
|
|
string(bytes) // ERROR "string\(bytes\) .* not used"
|
|
|
|
string(runes) // ERROR "string\(runes\) .* not used"
|
2020-12-04 10:40:39 -07:00
|
|
|
f0() // ok
|
|
|
|
f1() // ok
|
|
|
|
f2() // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
_ = f0() // ERROR "f0\(\) .*used as value"
|
2020-12-04 10:40:39 -07:00
|
|
|
_ = f1() // ok
|
|
|
|
_, _ = f2() // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
_ = f2() // ERROR "assignment mismatch: 1 variable but f2 returns 2 values|cannot assign"
|
2020-12-28 01:39:13 -07:00
|
|
|
_ = f1(), 0 // ERROR "assignment mismatch: 1 variable but 2 values|cannot assign"
|
2020-12-14 12:53:55 -07:00
|
|
|
T.M0 // ERROR "T.M0 .* not used"
|
|
|
|
t.M0 // ERROR "t.M0 .* not used"
|
|
|
|
cap // ERROR "use of builtin cap not in function call|must be called"
|
|
|
|
cap(slice) // ERROR "cap\(slice\) .* not used"
|
2020-12-04 10:40:39 -07:00
|
|
|
close(c) // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
_ = close(c) // ERROR "close\(c\) .*used as value"
|
|
|
|
func() {} // ERROR "func literal .* not used|is not used"
|
2020-12-04 10:40:39 -07:00
|
|
|
X{} // ERROR "undefined: X"
|
2020-12-14 12:53:55 -07:00
|
|
|
map[string]int{} // ERROR "map\[string\]int{} .* not used"
|
|
|
|
struct{}{} // ERROR "struct ?{}{} .* not used"
|
|
|
|
[1]int{} // ERROR "\[1\]int{} .* not used"
|
|
|
|
[]int{} // ERROR "\[\]int{} .* not used"
|
|
|
|
&struct{}{} // ERROR "&struct ?{}{} .* not used"
|
|
|
|
float32(x) // ERROR "float32\(x\) .* not used"
|
|
|
|
I(t) // ERROR "I\(t\) .* not used"
|
|
|
|
int(x) // ERROR "int\(x\) .* not used"
|
2020-12-04 10:40:39 -07:00
|
|
|
copy(slice, slice) // ok
|
|
|
|
_ = copy(slice, slice) // ok
|
|
|
|
delete(m, 1) // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
_ = delete(m, 1) // ERROR "delete\(m, 1\) .*used as value"
|
|
|
|
t.X // ERROR "t.X .* not used"
|
|
|
|
tp.X // ERROR "tp.X .* not used"
|
|
|
|
t.M // ERROR "t.M .* not used"
|
|
|
|
I.M // ERROR "I.M .* not used"
|
|
|
|
i.(T) // ERROR "i.\(T\) .* not used"
|
|
|
|
x == x // ERROR "x == x .* not used"
|
|
|
|
x != x // ERROR "x != x .* not used"
|
|
|
|
x != x // ERROR "x != x .* not used"
|
|
|
|
x < x // ERROR "x < x .* not used"
|
|
|
|
x >= x // ERROR "x >= x .* not used"
|
|
|
|
x > x // ERROR "x > x .* not used"
|
|
|
|
*tp // ERROR "\*tp .* not used"
|
|
|
|
slice[0] // ERROR "slice\[0\] .* not used"
|
|
|
|
m[1] // ERROR "m\[1\] .* not used"
|
|
|
|
len(slice) // ERROR "len\(slice\) .* not used"
|
|
|
|
make(chan int) // ERROR "make\(chan int\) .* not used"
|
|
|
|
make(map[int]int) // ERROR "make\(map\[int\]int\) .* not used"
|
|
|
|
make([]int, 1) // ERROR "make\(\[\]int, 1\) .* not used"
|
|
|
|
x * x // ERROR "x \* x .* not used"
|
|
|
|
x / x // ERROR "x / x .* not used"
|
|
|
|
x % x // ERROR "x % x .* not used"
|
|
|
|
x << x // ERROR "x << x .* not used"
|
|
|
|
x >> x // ERROR "x >> x .* not used"
|
|
|
|
x & x // ERROR "x & x .* not used"
|
|
|
|
x &^ x // ERROR "x &\^ x .* not used"
|
|
|
|
new(int) // ERROR "new\(int\) .* not used"
|
|
|
|
!b // ERROR "!b .* not used"
|
|
|
|
^x // ERROR "\^x .* not used"
|
|
|
|
+x // ERROR "\+x .* not used"
|
|
|
|
-x // ERROR "-x .* not used"
|
|
|
|
b || b // ERROR "b \|\| b .* not used"
|
2020-12-04 10:40:39 -07:00
|
|
|
panic(1) // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
_ = panic(1) // ERROR "panic\(1\) .*used as value"
|
2020-12-04 10:40:39 -07:00
|
|
|
print(1) // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
_ = print(1) // ERROR "print\(1\) .*used as value"
|
2020-12-04 10:40:39 -07:00
|
|
|
println(1) // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
_ = println(1) // ERROR "println\(1\) .*used as value"
|
2020-12-04 10:40:39 -07:00
|
|
|
c <- 1 // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
slice[1:1] // ERROR "slice\[1:1\] .* not used"
|
|
|
|
array[1:1] // ERROR "array\[1:1\] .* not used"
|
|
|
|
s[1:1] // ERROR "s\[1:1\] .* not used"
|
|
|
|
slice[1:1:1] // ERROR "slice\[1:1:1\] .* not used"
|
|
|
|
array[1:1:1] // ERROR "array\[1:1:1\] .* not used"
|
2020-12-04 10:40:39 -07:00
|
|
|
recover() // ok
|
|
|
|
<-c // ok
|
2020-12-14 12:53:55 -07:00
|
|
|
string(r) // ERROR "string\(r\) .* not used"
|
|
|
|
iota // ERROR "undefined: iota|cannot use iota"
|
|
|
|
real(cp) // ERROR "real\(cp\) .* not used"
|
|
|
|
imag(cp) // ERROR "imag\(cp\) .* not used"
|
|
|
|
complex(1, 2) // ERROR "complex\(1, 2\) .* not used"
|
|
|
|
unsafe.Alignof(t.X) // ERROR "unsafe.Alignof\(t.X\) .* not used"
|
|
|
|
unsafe.Offsetof(t.X) // ERROR "unsafe.Offsetof\(t.X\) .* not used"
|
|
|
|
unsafe.Sizeof(t) // ERROR "unsafe.Sizeof\(t\) .* not used"
|
|
|
|
_ = int // ERROR "type int is not an expression|not an expression"
|
|
|
|
(x) // ERROR "x .* not used|not used"
|
|
|
|
_ = new(x2) // ERROR "x2 is not a type|not a type"
|
|
|
|
// Disabled due to issue #43125.
|
|
|
|
// _ = new(1 + 1) // DISABLED "1 \+ 1 is not a type"
|
2020-12-04 10:40:39 -07:00
|
|
|
}
|