Commit 0d375381 authored by Konstantin Shaposhnikov's avatar Konstantin Shaposhnikov Committed by Rob Pike

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: 's avatarRob Pike <r@golang.org>
parent 530e2164
...@@ -23,6 +23,9 @@ func checkAtomicAssignment(f *File, node ast.Node) { ...@@ -23,6 +23,9 @@ func checkAtomicAssignment(f *File, node ast.Node) {
if len(n.Lhs) != len(n.Rhs) { if len(n.Lhs) != len(n.Rhs) {
return return
} }
if len(n.Lhs) == 1 && n.Tok == token.DEFINE {
return
}
for i, right := range n.Rhs { for i, right := range n.Rhs {
call, ok := right.(*ast.CallExpr) call, ok := right.(*ast.CallExpr)
......
...@@ -40,4 +40,13 @@ func AtomicTests() { ...@@ -40,4 +40,13 @@ func AtomicTests() {
*ap[1] = atomic.AddUint64(ap[0], 1) *ap[1] = atomic.AddUint64(ap[0], 1)
x = atomic.AddUint64() // Used to make vet crash; now silently ignored. 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
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment