Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/vet: atomic mistakes check seems confused about scope #15118

Closed
cespare opened this issue Apr 4, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@cespare
Copy link
Contributor

commented Apr 4, 2016

What version of Go are you using (go version)?

go 1.6

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

Consider a program like the following (play.golang.org link):

package main

import (
    "fmt"
    "sync/atomic"
)

func main() {
    var c int64
    for i := 0; i < 10; i++ {
        go func() {
            for {
                c := atomic.AddInt64(&c, 1)
                if c%10000000 == 0 {
                    fmt.Println(c)
                }
            }
        }()
    }
    select {}
}

What did you expect to see?

Since the c in the inner function is a different c from the outer atomic counter, I expected vet to not complain.

What did you see instead?

go vet gives the following output:

test.go:13: direct assignment to atomic value
@gopherbot

This comment has been minimized.

Copy link

commented Apr 5, 2016

CL https://golang.org/cl/21526 mentions this issue.

@gopherbot gopherbot closed this in 0d37538 Apr 6, 2016

@golang golang locked and limited conversation to collaborators Apr 6, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.