-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: false positives and wrong types across files, needs automatic recursive checking #20514
Comments
I'm unable to reproduce with Go 1.7.4: https://play.golang.org/p/dtO4-q8n2R None of these cause a vet warning. Interestingly, the third line doesn't, even though |
@alercah A strange issue is that as I mentioned this seems to be inconsistent. I can post a large repo of this with an example shortly. |
If you run "go install thepackage" first, does the error go away? If so, it's fixed in 1.9. |
@josharian Just using |
This should hopefully eliminate some false positives. golang/go#20514
@josharian This seems to happen with current tip (according to travis). As promised here is a concrete example (with -source): https://travis-ci.org/purpleidea/mgmt/jobs/237053430#L713 So AFAICT, I think we should re-open this issue. |
Where's the |
This does indeed look wrong. If I read correctly, the arguments to Logf in that line all appear to be strings, not *resources.FileRes. cc @valyala |
This should hopefully eliminate some false positives. golang/go#20514
This should hopefully eliminate some false positives. golang/go#20514
The resources/file.go:202 at commit 35f3529 looks like: log.Printf("%s: Watching: %s", obj, obj.path) // attempting to watch... Where Adding the following method to func (obj *FileRes) String() string { return "" } |
@valyala Indeed, however if you look closely: You'll see the https://github.com/purpleidea/mgmt/blob/feat/pgraph-cleanup/resources/resources.go#L444
and that
https://github.com/purpleidea/mgmt/blob/feat/pgraph-cleanup/resources/file.go#L48 So indeed the String method correctly exists. But go vet is not correctly detecting this since it's in a child (naming?) struct. |
CL https://golang.org/cl/44375 mentions this issue. |
It's strange, but now I cannot reproduce the issue neither with |
@valyala As I said it's weird! If I run a simplified (what I think is) equivalent to the issue, I don't see the problem. But If I run go vet on the whole code base I see the issue... |
If it's still an issue, it's usually helpful to reduce a minimal testcase
…On Mon, May 29, 2017, 12:58 James ***@***.***> wrote:
@valyala <https://github.com/valyala> As I said it's weird! If I run a
simplified (what I think is) equivalent to the issue, I don't see the
problem. But If I run go vet on the whole code base I see the issue...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20514 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AT4HVbEFykrUBgle_B34Mulo6VEWfUIBks5r-vkfgaJpZM4NohVy>
.
|
@alercah We're all aware, thanks! Would you like to help out in this area? |
@valyala I think I might have found the issue... Just putting together a test to prove my suspicions... |
@valyala The remaining issue turned out to be my fault in terms of usage, although as far as I'm concerned this should be considered a golang tooling bug: Go vet was getting called per file, so since the definition of String() string happened in a different file, it couldn't detect the issue. Changing my tests so that it runs Lastly, running go vet on a main package that includes many sub and sub-sub packages, doesn't recursively check all the contents! If this did, it would have avoided all of this nonsense to begin with. The fix: purpleidea/mgmt@46bda97 Hopefully my analysis is correct! Thanks for your time. |
@purpleidea, the issue is reproducible only if the package sources are put outside GOPATH. The issue cannot be reproduced after
So I'm unsure whether this is a bug. @robpike and @josharian , what do you think? |
Oh, I forgot to checkout the revision 35f3529 after
|
Running
If you run As for checking all packages, One could imagine adding a I do think that the difference in calling convention between So all in all, I'm not sure there is more to do for this specific issue, but I'm open to suggestions. |
@josharian Hmm.. I didn't realize it would work on a dir path. For some reason In any case, with this information, I just realized that this checks the vendor dir too, and something there always fails, so using it in this manner makes it difficult to use this as a test case, and we need to fall back to shell scripting to make this all work. I actually love shell, but I am a bit disappointed that the stock tools require shell wrapping to do what I think most users would want. |
I'll close this issue because my issue is worked-around with shell, and thanks for everyone's time and input. In a positive manner, if golang got rid of the CLA and the high barrier to getting code in, maybe more user patches would help round out the tools a bit better! Thanks again. |
This should help narrowing down the possible cause of #20514. Updates #20514. Change-Id: Ie997400c9749aace7783bd585b23dbb4cefc181d Reviewed-on: https://go-review.googlesource.com/44375 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
As for your vendor problem, see #17058 and #18085.
I do agree that we should reduce the barrier to contribution. (The CLA isn't going away, though.) However, I think the problem here is not willingness to implement a fix, but identifying exactly what needs to be fixed and what the fix is. |
This should hopefully eliminate some false positives. golang/go#20514
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.6.4 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOOS="linux"
GOARCH="amd64"
What did you do?
ran go vet
Code looks like:
log.Printf("foo: %s", whatever)
Replacing with
whatever.String()
solves the issue, but is unnecessarily verbose.What did you expect to see?
No error.
What did you see instead?
resources/foo.go:180: arg whatever for printf verb %s of wrong type: *foo.Whatever
The particularly strange thing is that the code is correct, and compiles and runs perfectly, however we get the warning from go vet, however not all cases are picked up. Some work without warning, and others don't.
The #go-nuts folks agreed this was an issue, but nobody knows if it was reported yet. It should be fairly easy to know if there is a
String() string
orfmt.Stringer
declared.Thanks!
The text was updated successfully, but these errors were encountered: