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: incorrect file and line number in repeated json tag warning #28995
Comments
Thanks for reporting. I think I know what the issue is. From the docs, we can see:
However, we do I can't see a quick fix here, other than having A perhaps simpler fix would be to simply name the other field with a qualified identifier, like @alandonovan any thoughts? |
Something interesting is that
@alandonovan I presume I should be using |
The position information should be correct for every types.Object relevant to the current package, which is a subset of its transitive imports. (The problem you are alluding to could occur if an Analyzer squirreled away Objects while analyzing one package and used them while analyzing in another package, but you would have to go out of your way to make that mistake.) The Analyzer code is correct. It looks to me like a bug in the handling of compiler export data, which is why it shows up in go vet (which used it) but not in x/tools/.../vet which ues only source. Unfortunately I can't reproduce it because the influx build appears to be broken. Could you provide me with a sequence of commands to check out a working influx build on which I can run vet?
cmd/vet designates the suite of analyzers and invokes unitchecker. I'm not sure I understand what you're asking. |
Ah, that makes sense.
The build worked for me the other day, and the latest HEAD today (see the commit hash above) still works fine. Perhaps you're not on Linux?
Having read your comment, what I'm asking is for a way to run vet in exactly the same way that I can of course add a debug println to |
Of course I don't want to derail this thread into a separate build problem... but we had been running into a module cache issue related to a kubernetes dependency and something with .gitattributes in the repository that was fixed in go1.11.2. If you're seeing output like
And you're on go1.11.2, you can (Related to kubernetes/kubernetes#69040 and #27925.) Or feel free to check out an even earlier revision - I believe this same issue was reproducible on master of influxdata/platform when the new vet switchover happened. |
Thanks Daniel, I can reproduce the problem now. (Apparently running from within GOPATH was my problem. Also I had to install bzr tool. First time I've ever encountered it in practice.) The root cause is that go/importer doesn't have a token.FileSet parameter even though logically it should, so it creates its own temporary FileSets then throws them away. The types.Package that go/importer returns have object positions that implicitly refer to to these inaccessible FileSets; when vet uses its own FileSet it gets the wrong answer. The solution is for go/importer to take an additional parameter. |
It's probably too late for this to go into 1.12. |
It's an API-compatible, low-risk change that fixes a clear bug. |
Thanks all. Doesn't look like it's a bug in the vet code I touched, so I'm unassigning myself for now. @alandonovan unless you would prefer that we work around this bug in Go 1.12's vet? It seems like giving wrong position information is worse than giving none at all. |
@alandonovan We are just before the beta. We're not going to change APIs at this point. |
Change https://golang.org/cl/152258 mentions this issue: |
Change https://golang.org/cl/152578 mentions this issue: |
importer.For does not populate the caller's token.FileSet leading to spurious position information in diagnostics. This change is the upstream fix for https://go-review.googlesource.com/c/go/+/152258. Fixes golang/go#28995 Change-Id: I9307d4f1f25c2b0877558426d4d71b3f1df99505 Reviewed-on: https://go-review.googlesource.com/c/152578 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran
go vet ./...
against github.com/influxdata/platform at revision 8279ba65c37c86586a8185afceb3dd73597a1e4b (master at the moment).I received the warning:
The phrase
struct field Cells repeats json tag "cells"
is understandable, but line 184 is a comment: https://github.com/influxdata/platform/blob/8279ba65c37c86586a8185afceb3dd73597a1e4b/http/dashboard_service.go#L184Line 76 is correct, however: https://github.com/influxdata/platform/blob/8279ba65c37c86586a8185afceb3dd73597a1e4b/http/dashboard_service.go#L76
Apparently it's because the struct that vet is flagging:
embeds platform.Dashboard which also has a field with json tag
cells
:But the line number and file don't match
dashboard_service.go:184
:https://github.com/influxdata/platform/blob/8279ba65c37c86586a8185afceb3dd73597a1e4b/dashboard.go#L49-L55
/cc @alandonovan
The text was updated successfully, but these errors were encountered: