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: false negative in shadow #12188

Closed
nicot opened this issue Aug 18, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@nicot
Copy link

commented Aug 18, 2015

Using the go tool vet -shadow command correctly reports shadowing in the following code:

func correct() {
    var a int
    {
        var a int
        a = 3
        fmt.Println(a)
    }
    fmt.Println(a)
}

However, running the same command on this code does not report any shadowing:

func broken() {
    var a int
    {
        a := 3
        fmt.Println(a)
    }
    fmt.Println(a)
}

I think there is a difference between the desired behavior and the implementation of idiomaticShortRedecl. If the right hand side AST node is not an ast.Ident or TypeAssertExpr, the whole function should fail and return false. Right now the function returns true even when the assignment being evaluated is not an idiomatic short redeclaration as described at the top of the function. I would like to submit a patch for this, if the implementation is not behaving as desired.

@NHOrus

This comment has been minimized.

Copy link

commented Aug 28, 2015

I experienced this false negative of cmd/vet while trying to debug following situation:
http://play.golang.org/p/d0Ks5bCELG

Both with -shadow and -shadowstruct

@gopherbot

This comment has been minimized.

Copy link

commented Oct 20, 2015

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

@golang golang locked and limited conversation to collaborators Oct 24, 2016

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.