go/test/used.go
Matthew Dempsky a800acaae1 [dev.typeparams] all: merge dev.regabi (07569da) into dev.typeparams
Conflicts:

- test/fixedbugs/issue27595.go
- test/fixedbugs/issue30087.go
- test/used.go

Merge List:

+ 2020-12-28 07569dac4e [dev.regabi] all: merge master (1d78139) into dev.regabi
+ 2020-12-28 76136be027 [dev.regabi] cmd/compile: check for recursive import in ImportBody
+ 2020-12-28 fda7ec3a3f [dev.regabi] cmd/compile: remove Name.IsDDD, etc
+ 2020-12-28 098a6490b9 [dev.regabi] cmd/compile: remove Declare in makepartialcall
+ 2020-12-28 137f0d2e06 [dev.regabi] cmd/compile: remove unnecessary Name.Sym call
+ 2020-12-28 3383b5c74a [dev.regabi] cmd/compile: flatten dependency graph [generated]
+ 2020-12-28 f8afb8216a [dev.regabi] cmd/compile: rename CommStmt and CaseStmt [generated]
+ 2020-12-28 5f3bd59a0d [dev.regabi] cmd/compile: remove some unneeded code in package ir
+ 2020-12-28 3bdafb0d82 [dev.regabi] cmd/compile: remove CommStmt.List
+ 2020-12-28 2ecf52b841 [dev.regabi] cmd/compile: separate CommStmt from CaseStmt
+ 2020-12-28 ed9772e130 [dev.regabi] cmd/compile: add explicit file name in types generation
+ 2020-12-28 a59d26603f [dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt
+ 2020-12-28 fbc4458c06 [dev.regabi] cmd/compile: simplify some tree traversal code
+ 2020-12-28 6c67677541 [dev.regabi] cmd/compile: simplify FuncName and PkgFuncName
+ 2020-12-28 676d794b81 [dev.regabi] cmd/compile: remove refersToCommonName
+ 2020-12-28 c98548e110 [dev.regabi] cmd/compile: merge ascompatee, ascompatee1, and reorder3
+ 2020-12-28 4c215c4fa9 [dev.regabi] cmd/compile: simplify and optimize reorder3
+ 2020-12-28 e6c973198d [dev.regabi] cmd/compile: stop mangling SelectorExpr.Sel for ODOTMETH
+ 2020-12-28 135ce1c485 [dev.regabi] cmd/compile: desugar OMETHEXPR into ONAME during walk
+ 2020-12-28 0f732f8c91 [dev.regabi] cmd/compile: minor walkExpr cleanups
+ 2020-12-28 0de8eafd98 [dev.regabi] cmd/compile: remove SelectorExpr.Offset field
+ 2020-12-28 a4f335f420 [dev.regabi] cmd/compile: always use a Field for ODOTPTR expressions
+ 2020-12-26 1d78139128 runtime/cgo: fix Android build with NDK 22
+ 2020-12-25 2018b68a65 net/mail: don't use MDT in test
+ 2020-12-25 e4f293d853 [dev.regabi] cmd/compile: fix OCALLMETH desugaring
+ 2020-12-25 1d9a1f67d5 [dev.regabi] cmd/compile: don't emit reflect data for method types
+ 2020-12-25 396b6c2e7c [dev.regabi] cmd/compile: cleanup assignment typechecking
+ 2020-12-25 e24d2f3d05 [dev.regabi] cmd/compile: remove typ from RangeStmt
+ 2020-12-25 2785c691c2 [dev.regabi] cmd/compile: cleanup devirtualization docs
+ 2020-12-25 4b1d0fe66f [dev.regabi] cmd/compile: new devirtualization pkg [generated]
+ 2020-12-24 082cc8b7d9 [dev.regabi] cmd/compile: change ir.IsAssignable -> ir.IsAddressable
+ 2020-12-24 27b248b307 [dev.regabi] cmd/compile: separate range stmt Vars to Key, Value nodes
+ 2020-12-23 40818038bf [dev.regabi] cmd/compile: change CaseStmt.Vars to Var
+ 2020-12-23 b116404444 runtime: shift timeHistogram buckets and allow negative durations
+ 2020-12-23 8db7e2fecd runtime: fix allocs-by-size and frees-by-size buckets
+ 2020-12-23 fb96f07e1a runtime: fix nStackRoots comment about stack roots
+ 2020-12-23 d1502b3c72 lib/time, time/tzdata: update tzdata to 2020e
+ 2020-12-23 30c99cbb7a cmd/go: add the Retract field to 'go help mod edit' definition of the GoMod struct
+ 2020-12-23 49d0b239cb doc: fix a typo in contribute.html
+ 2020-12-23 9eeed291bc [dev.regabi] cmd/compile: eliminate usage of ir.Node in liveness
+ 2020-12-23 d1d64e4cea [dev.regabi] cmd/compile: split SliceExpr.List into separate fields
+ 2020-12-23 98a73030b0 cmd/go: in 'go get', promote named implicit dependencies to explicit
+ 2020-12-23 d19018e8f1 [dev.regabi] cmd/compile: split SliceHeaderExpr.LenCap into separate fields
+ 2020-12-23 53f082b0ee [dev.regabi] cmd/compile: cleanup export code further
+ 2020-12-23 31267f82e1 [dev.regabi] cmd/compile: simplify function/interface/struct typechecking
+ 2020-12-23 addade2cce [dev.regabi] cmd/compile: prefer types constructors over typecheck
+ 2020-12-23 18ebfb49e9 [dev.regabi] cmd/compile: cleanup noder
+ 2020-12-23 87a592b356 [dev.regabi] cmd/compile: cleanup import/export code
+ 2020-12-23 5898025026 [dev.regabi] cmd/compile: update mkbuiltin.go to use new type constructors
+ 2020-12-23 63c96c2ee7 [dev.regabi] cmd/compile: update mkbuiltin.go and re-enable TestBuiltin
+ 2020-12-23 fd6ba1c8a2 os/signal: fix a deadlock with syscall.AllThreadsSyscall() use
+ 2020-12-23 b0b0d98283 runtime: linux iscgo support for not blocking nptl signals
+ 2020-12-22 223331fc0c cmd/go/internal/modload: add hint for missing implicit dependency

Change-Id: Iecb8a7dfb401b6ab383e97101cd81bfc201683f6
2020-12-28 00:39:17 -08:00

145 lines
6 KiB
Go

// 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
var x, x1, x2 int
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!
x1 // ERROR "x1 .* not used"
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"
f0() // ok
f1() // ok
f2() // ok
_ = f0() // ERROR "f0\(\) .*used as value"
_ = f1() // ok
_, _ = f2() // ok
_ = f2() // ERROR "assignment mismatch: 1 variable but f2 returns 2 values|cannot assign"
_ = f1(), 0 // ERROR "assignment mismatch: 1 variable but 2 values|cannot assign"
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"
close(c) // ok
_ = close(c) // ERROR "close\(c\) .*used as value"
func() {} // ERROR "func literal .* not used|is not used"
X{} // ERROR "undefined: X"
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"
copy(slice, slice) // ok
_ = copy(slice, slice) // ok
delete(m, 1) // ok
_ = 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"
panic(1) // ok
_ = panic(1) // ERROR "panic\(1\) .*used as value"
print(1) // ok
_ = print(1) // ERROR "print\(1\) .*used as value"
println(1) // ok
_ = println(1) // ERROR "println\(1\) .*used as value"
c <- 1 // ok
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"
recover() // ok
<-c // ok
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"
}