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: -shadow can't detect shadowing in select statement #15362

fffw opened this issue Apr 19, 2016 · 2 comments


None yet
3 participants
Copy link

commented Apr 19, 2016

go tool vet -shadow . didn't report anything for example code below. Tested both go 1.5.3 and 1.6.

package main

import "fmt"

func main() {
    ch1 := make(chan int)
    ch2 := make(chan int)
    go func() {
        ch1 <- 1
        ch2 <- 2
    var result int
    for i := 0; i < 2; i++ {
        select {
        case result = <-ch1:
        case result := <-ch2: // <-- shadowing
    fmt.Println(result) // expect 2, got 1

This comment has been minimized.

Copy link

commented Apr 19, 2016

This works with tip:

go tool vet -shadow 1.go
1.go:17: declaration of "result" shadows declaration at 1.go:12

This comment has been minimized.

Copy link

commented Apr 19, 2016

Wow that is great! I just didn't find relevant issues before creating this one.

@fffw fffw closed this Apr 19, 2016

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