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: complains about captured range var that's actually a field name #13236

Closed
Sajmani opened this issue Nov 13, 2015 · 1 comment

Comments

Projects
None yet
4 participants
@Sajmani
Copy link
Contributor

commented Nov 13, 2015

go version devel +4df6dcb Wed Jul 22 16:12:06 2015 -0400 linux/amd64

Vet complains that "v" is captured by this loop; it isn't:

package main

import "fmt"

func main() {
    list := []int{1, 2, 3}
    type s struct {
        v int
    }
    c := make(chan s)
    for v := range list {
        go func(vv int) {
            c <- s{v: vv} // vet complains that v is captured here
        }(v)
    }
    for range list {
        fmt.Println(<-c)
    }
}

Output:

% go run main.go      
{2}
{0}
{1}
% go tool vet main.go
main.go:13: range variable v captured by func literal

@ianlancetaylor ianlancetaylor changed the title x/tools/cmd/vet: complains about captured range var that's actually a field name cmd/vet: complains about captured range var that's actually a field name Nov 14, 2015

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Nov 14, 2015

@gopherbot

This comment has been minimized.

Copy link

commented Mar 26, 2016

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

@gopherbot gopherbot closed this in 4ffa5eb Mar 27, 2016

@golang golang locked and limited conversation to collaborators Mar 27, 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.