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: bombs out before reporting all errors #31619

davecheney opened this issue Apr 22, 2019 · 3 comments

cmd/vet: bombs out before reporting all errors #31619

davecheney opened this issue Apr 22, 2019 · 3 comments


Copy link

@davecheney davecheney commented Apr 22, 2019

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

% go version
go version devel +68d4b1265e Sat Apr 20 19:34:03 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?


What did you do?

(~/devel/vet) % ls
go.mod          go.sum          tools.go
(~/devel/vet) % cat go.mod

go 1.13

require v0.0.0-20190310220240-1b9ccfa71afe
(~/devel/vet) % cat tools.go 
// +build tools
package main

import _ ""

What did you expect to see?

% go vet
./tools.go:1:1: +build comment must appear before package clause and be followed by a blank line
tools.go:4:8: import "" is a program, not an importable package

What did you see instead?

(~/devel/vet) % go vet
tools.go:4:8: import "" is a program, not an importable package

The failure to report the incorrect build tag on line 1 is masked by the complaint about the non importable package.

@dmitshur dmitshur changed the title go vet bombs out before reporting all errors cmd/vet: bombs out before reporting all errors Apr 22, 2019
@dmitshur dmitshur added this to the Go1.13 milestone Apr 22, 2019
Copy link

@ianthehat ianthehat commented Apr 22, 2019

I am not the expert in that code, but I don't think this is fixable, or in fact a bug.
go vet requires a program to successfully parse and typecheck before it starts running the actual vet checks, that error is from the load imports phase which is before vet runs at all. You will get the same error from go build


Copy link

@mvdan mvdan commented Apr 23, 2019

Agreed with @ianthehat. We could perhaps hack vet to run a subset of the checks (like the build tag one) before type-checking, but that would probably result in added complexity for little benefit.


Copy link
Contributor Author

@davecheney davecheney commented Apr 23, 2019

I think fixing this would provide significant benefit. The issue came from inside my company where a developer spent a day trying to figure out what was wrong with their tools.go file--a cute hack that appears to have metastasised across Go codebases. My snooty response that go vet would catch this was undermind by the fact that even though this file is sufficient to drive the go mod mechanisms vet is too picky to spot the obvious error on line one; the line that would have helped it avoid spending time on the rest of the file.


@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@andybons andybons added this to the Go1.14 milestone Jul 8, 2019
@rsc rsc removed this from the Go1.14 milestone Oct 9, 2019
@rsc rsc added this to the Backlog milestone Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants