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 positive #39949

Closed
martinrode opened this issue Jun 30, 2020 · 3 comments
Closed

cmd/vet: false positive #39949

martinrode opened this issue Jun 30, 2020 · 3 comments

Comments

@martinrode
Copy link

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

$ go version
go version go1.14.3 darwin/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="on"
GOARCH="amd64"
GOBIN="/Users/martin/go/bin"
GOCACHE="/Users/martin/Library/Caches/go-build"
GOENV="/Users/martin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/martin/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/martin/go/src/github.com/programmfabrik/fylr/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4f/l31kb4n521d6g89qxrwcx69h0000gp/T/go-build954182719=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

main.go

// +build "go1.14"

package main

var myCmd string = ""

func main() {
	// empty
	println("henk")
}

dummy.go

package main

func init() {
	myCmd = "horst"
}

$ go vet

What did you expect to see?

  • go vet should not report an issue
  • when compiling without the dummy.go file, go vet also wrongly reports an issue

What did you see instead?

  • vet: ./dummy.go:4:2: undeclared name: myCmd
  • the problems are caused by the "+build" line
@seankhliao
Copy link
Member

seankhliao commented Jun 30, 2020

the version tags looks like // +build go1.14 without the quotes

vet is correct in reporting that the current configuration has an undefined variable. Also your code does not compile

@ianlancetaylor
Copy link
Contributor

Closing because as commented above this seems to be correct behavior. Please comment if you disagree.

@martinrode
Copy link
Author

Ok, I just realized the +build tag with the quotes is wrong. It would be an improvement if go vet / go build would report that rather than the misleading error messages.

@golang golang locked and limited conversation to collaborators Jul 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants