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
Open

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

davecheney opened this issue Apr 22, 2019 · 3 comments
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@davecheney
Copy link
Contributor

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 22, 2019
@dmitshur dmitshur added this to the Go1.13 milestone Apr 22, 2019
@ianthehat
Copy link

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
Copy link
Member

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.

@davecheney
Copy link
Contributor Author

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
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants