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

Closed
fffw opened this issue Apr 19, 2016 · 2 comments
Closed

cmd/vet: -shadow can't detect shadowing in select statement #15362

fffw opened this issue Apr 19, 2016 · 2 comments

Comments

@fffw
Copy link

fffw 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:
            fmt.Println(result)
        case result := <-ch2: // <-- shadowing
            fmt.Println(result)
        }
    }
    fmt.Println(result) // expect 2, got 1
}
@kostya-sh
Copy link
Contributor

This works with tip:

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

@fffw
Copy link
Author

fffw commented Apr 19, 2016

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

@fffw fffw closed this as completed 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.
Projects
None yet
Development

No branches or pull requests

3 participants