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

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 opened this issue Aug 13, 2020 · 2 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@graywolf-at-work
Copy link

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.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Aug 13, 2020
@gopherbot gopherbot added this to the Unreleased milestone Aug 13, 2020
@andybons
Copy link
Member

@matloob

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 13, 2020
@matloob
Copy link
Contributor

matloob commented Sep 14, 2020

Yes it's like a bug that the names of the files affects the results. Shadow is an experimental analysis so we're not actively working on it, but if you want to work on this and fix it, feel free!

@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants