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: Incorrect warning shown when code isn't built #15787

Closed
mpolden opened this issue May 21, 2016 · 5 comments

Comments

Projects
None yet
4 participants
@mpolden
Copy link

commented May 21, 2016

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

    $ go version
    go version devel +1f8d276 Sat May 21 01:30:43 2016 +0000 linux/amd64
    
  2. What operating system and processor architecture are you using (go env)?

    $ go env
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="linux"
    GOOS="linux"
    GOPATH=""
    GORACE=""
    GOROOT="/tmp/go"
    GOTOOLDIR="/tmp/go/pkg/tool/linux_amd64"
    CC="gcc"
    GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build009147319=/tmp/go-build -gno-record-gcc-switches"
    CXX="g++"
    CGO_ENABLED="1"
    
  3. What did you do?
    I ran go vet on the following program: https://play.golang.org/p/-AbGnFT_3W

    The struct foo is intentionally undefined. The same problem occurs if foo is defined in another package, and that package hasn't been built yet.

  4. What did you expect to see?

    No warnings reported by go vet (this is the case when using 1.6).

  5. What did you see instead?

    $ go vet main.go
    main.go:16: first argument to Fprintln is os.Stdout
    exit status 1
    

It seems that building the code is required before running go vet now, is this an intentional change from 1.6?

mpolden added a commit to mpolden/lftpq that referenced this issue May 21, 2016

mpolden added a commit to mpolden/lftpq that referenced this issue May 21, 2016

@valyala

This comment has been minimized.

Copy link
Contributor

commented May 23, 2016

I'll look into this issue on this week

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented May 24, 2016

Some vet tests do require that the packages be built, so that vet can do type checking. Some vet tests do not require this. As far as I know nothing in this regard has changed since 1.6.

What has changed here is the test. The test looks for the function name and guesses based on the name what it does. It looks for a set of names. Since the 1.6 release, the following names were added: fprintln, panicln, println, sprintln. That's why 1.6 doesn't warn.

It's not clear to me that this is worth fixing. The nature of the vet program is that some errors are false positives, especially if the code has not been built. You can disable the test for your code base with go tool vet -printf=false.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone May 24, 2016

@valyala

This comment has been minimized.

Copy link
Contributor

commented May 24, 2016

@ianlancetaylor , this may be easily fixed - see the CL.

@gopherbot

This comment has been minimized.

Copy link

commented May 24, 2016

CL https://golang.org/cl/23351 mentions this issue.

@mpolden

This comment has been minimized.

Copy link
Author

commented May 24, 2016

@ianlancetaylor I'm aware that go vet might produce false positives, but it wasn't immediately obvious that building packages would impact the reported errors in this case.

I spent some time trying to reproduce it, as it only happens in a clean environment (where nothing has been built in the past), e.g. when using Travis CI.

@gopherbot gopherbot closed this in dcc42c7 May 24, 2016

@golang golang locked and limited conversation to collaborators May 24, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.