]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: do not treat declaration as asignment in atomic check
authorKonstantin Shaposhnikov <k.shaposhnikov@gmail.com>
Tue, 5 Apr 2016 15:54:50 +0000 (23:54 +0800)
committerRob Pike <r@golang.org>
Wed, 6 Apr 2016 16:38:24 +0000 (16:38 +0000)
Fixes #15118

Change-Id: Iad56ed412535c8ac0a01c4bd7769fd3d37688ac9
Reviewed-on: https://go-review.googlesource.com/21526
Run-TryBot: Rob Pike <r@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/vet/atomic.go
src/cmd/vet/testdata/atomic.go

index c084f13ab3fcdfafcd0cf427312dd1e32194f61a..b2ca2d80f304ec35ec54267c48d3a751fb47f1cd 100644 (file)
@@ -23,6 +23,9 @@ func checkAtomicAssignment(f *File, node ast.Node) {
        if len(n.Lhs) != len(n.Rhs) {
                return
        }
+       if len(n.Lhs) == 1 && n.Tok == token.DEFINE {
+               return
+       }
 
        for i, right := range n.Rhs {
                call, ok := right.(*ast.CallExpr)
index 1ba261d9412a2b47684e113f4562b447c1cf80e2..d5a8e61184477d5fb9b9dc085fe5e52658f6992e 100644 (file)
@@ -40,4 +40,13 @@ func AtomicTests() {
        *ap[1] = atomic.AddUint64(ap[0], 1)
 
        x = atomic.AddUint64() // Used to make vet crash; now silently ignored.
+
+       {
+               // A variable declaration creates a new variable in the current scope.
+               x := atomic.AddUint64(&x, 1) // ERROR "declaration of .x. shadows declaration at testdata/atomic.go:16"
+
+               // Re-declaration assigns a new value.
+               x, w := atomic.AddUint64(&x, 1), 10 // ERROR "direct assignment to atomic value"
+               _ = w
+       }
 }