summaryrefslogtreecommitdiff
path: root/src/cmd/vet/test_assign.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/vet/test_assign.go')
-rw-r--r--src/cmd/vet/test_assign.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/cmd/vet/test_assign.go b/src/cmd/vet/test_assign.go
new file mode 100644
index 000000000..8e0f45e53
--- /dev/null
+++ b/src/cmd/vet/test_assign.go
@@ -0,0 +1,20 @@
+// 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.
+
+// This file contains tests for the useless-assignment checker.
+
+// +build vet_test
+
+package main
+
+type ST struct {
+ x int
+}
+
+func (s *ST) SetX(x int) {
+ // Accidental self-assignment; it should be "s.x = x"
+ x = x // ERROR "self-assignment of x to x"
+ // Another mistake
+ s.x = s.x // ERROR "self-assignment of s.x to s.x"
+}