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

Open
davecheney opened this issue Apr 22, 2019 · 3 comments

Comments

@davecheney
Copy link
Contributor

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?

yes

What did you do?

(~/devel/vet) % ls
go.mod          go.sum          tools.go
(~/devel/vet) % cat go.mod
module github.com/davecheney/vetbug

go 1.13

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

import _ "mvdan.cc/unparam"

What did you expect to see?

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

What did you see instead?

(~/devel/vet) % go vet
tools.go:4:8: import "mvdan.cc/unparam" 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

@ianthehat

This comment has been minimized.

Copy link

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

@mvdan

This comment has been minimized.

Copy link
Member

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.

@davecheney

This comment has been minimized.

Copy link
Contributor Author

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 modified the milestones: Go1.13, Go1.14 Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.