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: shadowed variables check doesn't catch shadowing from short assignment in if statements #14494

stevekuznetsov opened this issue Feb 24, 2016 · 4 comments


Copy link

@stevekuznetsov stevekuznetsov commented Feb 24, 2016

For the following example:

package main

import (

func main() {
    if len(os.Args) != 2 {
        log.Fatal("Usage: jsonformat.go <filename>")

    byt, err := ioutil.ReadFile(os.Args[1])
    if err != nil {
        log.Fatalf("ERROR: Unable to read file %q: %v\n", os.Args[1], err)

    var dat map[string]interface{}

    if err := json.Unmarshal(byt, &dat); err != nil { // this err is not flagged as masking the err in the outer scope, incorrectly
        log.Fatalf("ERROR: Invalid JSON file  '%v': %v\n", os.Args[1], err)

    if output, err := json.MarshalIndent(dat, "", "  "); err != nil { // this err is flagged as masking the err in the outer scope, correctly
        log.Fatalf("ERROR: Unable to indent JSON file: %v\n", os.Args[1])
    } else {
        os.Stdout.Write(append(output, '\n'))

One the errors is not flagged correctly, even when using -shadowstrict. My version of go tool vet is at 108746816ddf01ad0c2dbea08a1baef08bc47313

Copy link

@ianlancetaylor ianlancetaylor commented Feb 25, 2016

This is fixed in Go 1.6, though I do not know what fixed it.

Copy link

@stevekuznetsov stevekuznetsov commented Feb 25, 2016

I updated my version of go vet with a go get -u today... Should that not have picked up this change?

Copy link

@kostya-sh kostya-sh commented Feb 25, 2016

I believe this was fixed by 3c1712d

@stevekuznetsov, vet is part of Go tool set since Go 1.5. is no longer maintained.

I think should be deleted at some point as it creates a lot of confusion.

@golang golang locked and limited conversation to collaborators Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants