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: -<analyzer> flags don't work when outside of GOROOT #35837

Closed
shawn-xdji opened this issue Nov 26, 2019 · 5 comments
Milestone

Comments

@shawn-xdji
Copy link
Contributor

@shawn-xdji shawn-xdji commented Nov 26, 2019

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

$ go version
go version devel +95be9b7559 Fri Nov 22 04:26:34 2019 +0000 linux/amd64

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/xiaji01/.cache/go-build"
GOENV="/home/xiaji01/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xiaji01/.go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/xiaji01/util/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/xiaji01/util/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-build905003963=/tmp/go-build -gno-record-gcc-switches"

What did you do?

~/util/go$ go vet runtime/testdata/testprog
# runtime/testdata/testprog
src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code

~/util/go$ go vet -unreachable=false runtime/testdata/testprog
# runtime/testdata/testprog
src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code

What did you expect to see?

-unreachable=false works even running 'go vet' outside <go root>/src

What did you see instead?

the unreachable warning is not suppressed.

@shawn-xdji

This comment has been minimized.

Copy link
Contributor Author

@shawn-xdji shawn-xdji commented Nov 26, 2019

I have a local fix, would like to send it for reviewing if this is a bug.

@dmitshur dmitshur added this to the Backlog milestone Nov 26, 2019
@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Nov 26, 2019

@alandonovan

This comment has been minimized.

Copy link
Contributor

@alandonovan alandonovan commented Nov 26, 2019

Thanks, this does indeed look like a bug. Please do share your fix.

$ go version
go version devel +4a378d712d Tue Nov 26 20:21:04 2019 +0000 linux/amd64

$ cd $GOROOT/src
$ go vet -unreachable=true runtime/testdata/testprog
# runtime/testdata/testprog
runtime/testdata/testprog/deadlock.go:45:2: unreachable code
runtime/testdata/testprog/deadlock.go:50:2: unreachable code
$ go vet -unreachable=false runtime/testdata/testprog
$

$ cd $HOME
$ go vet -unreachable=true runtime/testdata/testprog
# runtime/testdata/testprog
go-again/src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
go-again/src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code
$ go vet -unreachable=false runtime/testdata/testprog
# runtime/testdata/testprog
go-again/src/runtime/testdata/testprog/deadlock.go:45:2: unreachable code
go-again/src/runtime/testdata/testprog/deadlock.go:50:2: unreachable code
@alandonovan alandonovan changed the title cmd/vet: vet flags for specifying 'analyzer' doesn't work cmd/vet: -<analyzer> flags don't work when outside of GOROOT Nov 26, 2019
@shawn-xdji

This comment has been minimized.

Copy link
Contributor Author

@shawn-xdji shawn-xdji commented Nov 29, 2019

Thanks for confirming.
The flags specified on 'go vet' command line will be overwritten if:
1. the package under vetting is resolved by searching under $GOROOT/src (after the local import fails to find a matched one), and
2. no options for 'go tool vet' are specified
3. no vettool is specified
There might be various fixes, I chose to replace the overwriting with appending, thought it would minimize the impact, make sense?

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Dec 2, 2019

Change https://golang.org/cl/209498 mentions this issue: cmd/vet: honor analyzer flags when running vet outside $GOROOT/src

@gopherbot gopherbot closed this in 2ac1ca9 Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.