1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:54:42 -07:00

cmd/vet: do not treat declaration as asignment in atomic check

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>
This commit is contained in:
Konstantin Shaposhnikov 2016-04-05 23:54:50 +08:00 committed by Rob Pike
parent 530e216494
commit 0d37538196
2 changed files with 12 additions and 0 deletions

View 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)

View 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
}
}