-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: build tags in raw string literals should be ignored #13533
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
Comments
Build tags detection by the go build system is by design line oriented to avoid unnecessary parsing. The vet tool does the same thing, which seems correct to me. |
@cznic That is a fair point, but in this case the other tools are not going to recognize the +build comment, which is what cmd/vet is saying anyhow. In a case like this it seems worth skipping raw string literals if not too complicated. |
This bug is actually a duplicate of #12269, I guess no one spotted that. That bug was closed by @robpike with the given reason "Not worth the trouble to fix." I've hit this bug myself (here - tmthrgd/go-bindata#4), it's nothing all too major of course. Although it would be nice if go vet wasn't throwing up this false positive. Is there any chance this bug might get fixed or is it still "not worth the trouble"? |
@ianlancetaylor Skipping raw string literals means recognizing them which requires full lexing (unless I'm missing some shortcut). That's probably more expensive than what we do now (to be verified). It seems a bit of overkill given that it's trivial to work around this issue (use a regular string and string concatenation as needed). |
Yes, it's probably not worth doing. Closing. |
This is pretty firmly a bug in go vet (see golang/go#12269 and golang/go#13533), but is considered not worth the effort to fix by the Go authors. This is a workaround and I don't love it, but it's not objectively hideous.
Now that vet is on by default, and we are aiming for 100% accuracy on such checks, and we’ve gotten a handful of dups of this recently, I think we should consider fixing this. Yes, parsing is more expensive than line-oriented searches, but compared to the rest of vet, which does full typechecking, I doubt it matters much, particularly since we only need parse up to the package clause. |
Scratch the comment about only parsing to the package clause. Still shouldn’t be too expensive. |
Only lexing (scanning) is needed, no parsing. |
I would think the right fix is a complete rewrite of the module that looks at the comment-decorated parse tree, which we have. The parse will honor valid build comments but disregard bad ones, which would still be present as comments in the tree. |
I'm going to give this a go - my current thinking is that since vet now always has the I had initially re-written |
Change https://golang.org/cl/111415 mentions this issue: |
Go 1.10 runs go vet during go test automatically; unfortunately go vet fires a false positive triggered by a build tag appearing in a template string literal. Will be fixed in Go 1.11 See golang/go#13533
main.go
:Running
vet
produces:This also contributes to noise in the vet output for core, e.g.
The text was updated successfully, but these errors were encountered: