summaryrefslogtreecommitdiff
path: root/test/fixedbugs/issue4654.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2013-02-01 21:02:15 -0500
committerRuss Cox <rsc@golang.org>2013-02-01 21:02:15 -0500
commit23e92e93a7200b7a2448eb35b7468c1da9eab7a8 (patch)
tree3549d7b2bd8e438926fd9bf8ce3dc1bbc7ffeaba /test/fixedbugs/issue4654.go
parente3055a936199e1285451bb2002eee6b14894c25e (diff)
downloadgo-23e92e93a7200b7a2448eb35b7468c1da9eab7a8.tar.gz
cmd/gc: clearer error for defer/go of conversion or invalid function call
Fixes issue 4654. R=ken2 CC=golang-dev https://codereview.appspot.com/7229072
Diffstat (limited to 'test/fixedbugs/issue4654.go')
-rw-r--r--test/fixedbugs/issue4654.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/fixedbugs/issue4654.go b/test/fixedbugs/issue4654.go
new file mode 100644
index 000000000..ede7f56e7
--- /dev/null
+++ b/test/fixedbugs/issue4654.go
@@ -0,0 +1,71 @@
+// errorcheck
+
+// Copyright 2013 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.
+
+// Issue 4654.
+// Check error for conversion and 'not used' in defer/go.
+
+package p
+
+import "unsafe"
+
+func f() {
+ defer int(0) // ERROR "defer requires function call, not conversion"
+ go string([]byte("abc")) // ERROR "go requires function call, not conversion"
+
+ var c complex128
+ var f float64
+ var t struct {X int}
+
+ var x []int
+ defer append(x, 1) // ERROR "defer discards result of append"
+ defer cap(x) // ERROR "defer discards result of cap"
+ defer complex(1, 2) // ERROR "defer discards result of complex"
+ defer complex(f, 1) // ERROR "defer discards result of complex"
+ defer imag(1i) // ERROR "defer discards result of imag"
+ defer imag(c) // ERROR "defer discards result of imag"
+ defer len(x) // ERROR "defer discards result of len"
+ defer make([]int, 1) // ERROR "defer discards result of make"
+ defer make(chan bool) // ERROR "defer discards result of make"
+ defer make(map[string]int) // ERROR "defer discards result of make"
+ defer new(int) // ERROR "defer discards result of new"
+ defer real(1i) // ERROR "defer discards result of real"
+ defer real(c) // ERROR "defer discards result of real"
+ defer append(x, 1) // ERROR "defer discards result of append"
+ defer append(x, 1) // ERROR "defer discards result of append"
+ defer unsafe.Alignof(t.X) // ERROR "defer discards result of unsafe.Alignof"
+ defer unsafe.Offsetof(t.X) // ERROR "defer discards result of unsafe.Offsetof"
+ defer unsafe.Sizeof(t) // ERROR "defer discards result of unsafe.Sizeof"
+
+ defer copy(x, x) // ok
+ m := make(map[int]int)
+ defer delete(m, 1) // ok
+ defer panic(1) // ok
+ defer print(1) // ok
+ defer println(1) // ok
+ defer recover() // ok
+
+ int(0) // ERROR "int\(0\) not used"
+ string([]byte("abc")) // ERROR "string\(\[\]byte literal\) not used"
+
+ append(x, 1) // ERROR "not used"
+ cap(x) // ERROR "not used"
+ complex(1, 2) // ERROR "not used"
+ complex(f, 1) // ERROR "not used"
+ imag(1i) // ERROR "not used"
+ imag(c) // ERROR "not used"
+ len(x) // ERROR "not used"
+ make([]int, 1) // ERROR "not used"
+ make(chan bool) // ERROR "not used"
+ make(map[string]int) // ERROR "not used"
+ new(int) // ERROR "not used"
+ real(1i) // ERROR "not used"
+ real(c) // ERROR "not used"
+ append(x, 1) // ERROR "not used"
+ append(x, 1) // ERROR "not used"
+ unsafe.Alignof(t.X) // ERROR "not used"
+ unsafe.Offsetof(t.X) // ERROR "not used"
+ unsafe.Sizeof(t) // ERROR "not used"
+}