-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: cmd/vet: warn about // go:...
#50898
Comments
dup of #43698 ? |
Change https://golang.org/cl/381914 mentions this issue: |
I've mailed out a new static analyzer "pragmyzer" in CL https://go-review.googlesource.com/c/tools/+/381914 which fixes the problem and is simple. Thank you for pointing that out @seankhliao, indeed in a limited case that that issue only requests for cmd/vet! However, I still think perhaps we should consider having the compiler actually fail to compile hence I shall keep this one open for proposal review. |
My take is that a vet check is enough, as long as it runs as part of |
// go:...
That being said, perhaps the most straightforward way is indeed to take the logic from "pragmyzer" and push it into buildtag analyzer? |
// go:...
// go:...
I changed this to be a cmd/vet proposal. |
// go:...
// go:...
There is already a buildtag vet check. That should be extended if needed. |
This proposal has been added to the active column of the proposals project |
This was already accepted for |
Also worth noting that I already suggested using a compiler/build error in #43698 (comment), and it seems like the idea was already discarded in favor of vet. So I agree with @seankhliao that this seems like a dupe; it's far too easy to forget that a proposal has already been filed, even when you've participated in the previous one! :) |
Thanks for digging that up! |
This proposal is a duplicate of a previously discussed proposal, as noted above, |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?Irrelevant
What did you do?
From some internal code at Orijtech Inc that caused unexpected problems after runtime and deployment; it used an embed pragma statement to embed a file but unfortunately we had a space so
// go:embed file.txt
instead of//go:embed file.txt
, the code compiled alright and was deployed but caused a bit of a scare until a colleague noticed the bug.What did you expect to see?
I expected an error reported by a static analyzer or that it fails to compile this code. We have advanced tooling but unfortunately we are still letting such bugs go through. I really think that the compiler should do more to help out users flag such problems. I worked on an initiative such as in CL https://go-review.googlesource.com/c/go/+/34562/ which @randall77 alternated and nailed in https://go-review.googlesource.com/c/go/+/45010 to reject unknown pragmas in the standard library. I expected either a static analyzer report something such as
We should try as much to make our users very successful
What did you see instead?
To solve this problem I wrote a static analyzer internally that I'd be delighted to open source or even write a pass for, for x/go/analysis or to contribute a compiler patch.
The text was updated successfully, but these errors were encountered: