Skip to content

x/tools/go/analysis/passes/shadow/cmd/shadow: Failure/success of the linter depends also on filename, not just the content #40758

Open
@graywolf-at-work

Description

@graywolf-at-work

What version of Go are you using (go version)?

$ go version
1.14.6

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/wolf/.cache/go-build"
GOENV="/home/wolf/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="go.showmax.cc,go.platfoo.cc"
GONOSUMDB="go.showmax.cc,go.platfoo.cc"
GOOS="linux"
GOPATH="/home/wolf/go"
GOPRIVATE="go.showmax.cc,go.platfoo.cc"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build056422182=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Install shadow vet:

    $ go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow

  2. Create following files:

    +$ tree .
    .
    ├── b.go
    ├── c.go
    └── go.mod

    0 directories, 3 files
    +$ cat b.go
    package foo

    func newX() int {
    x := 1
    return x
    }

    var x = newX()
    +$ cat c.go
    package foo

    func f() {
    x = 1
    }
    +$ cat go.mod
    module foo

    go 1.14

  3. Run the shadow vet:

    $ go vet -vettool=/home/wolf/go/bin/shadow ./...

What did you expect to see?

# foo
./b.go:4:2: declaration of "x" shadows declaration at line 8

What did you see instead?

Nothing.

Some research notes

It looks like shadow vet depends on the filenames, because all one needs to do
to get the expected output is to rename c.go to a.go, so when sorted by
alphabet is is before b.go. My understanding is that the package is the
scope, so alphabetic ordering of the files should not matter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AnalysisIssues related to static analysis (vet, x/tools/go/analysis)NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions