-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: false positive about wrong type in printf when struct with unexported field is printed #23563
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
This seems to be related to unexported interface fields - this is a smaller reproducer:
|
Change https://golang.org/cl/90516 mentions this issue: |
I'm going to redirect this to 1.10 because with 1.10 this occurs when running |
@ianlancetaylor please see all the other recent vet issues that OP raised. These could all be considered regressions in 1.10, given how vet is now run as part of test. I have sent CLs for 4 of these already. |
As I more or less said on the CL, I'm not yet convinced that this is a bug. The right way to print a value of type |
@ianlancetaylor you may be right. However, note that my CL affects all interfaces, not just error and fmt.Stringer. Perhaps the CL should keep the warning for those types. Edit: what I mean is that vet could warn on |
@mvdan Is that not how it works today? |
@ianlancetaylor not exactly - see my full example in #23563 (comment). The So I agree that OP's example is working as intended (even if the program technically works), but I think that the current heuristic is too aggressive. It should only cover types that we know to have |
Thanks, that sounds reasonable. I guess we should also warn about uncallable |
I think this will fix an error in go 1.10 which may or may not be a false positive. I think it's the same as what's discussed here: golang/go#23563 (comment) Since I don't have go 1.10 locally, I'm going to push it up and see if it fixes the Travis-CI build. :) https://travis-ci.org/asjoyner/shade/jobs/444793514
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.10rc1 darwin/amd64
Does this issue reproduce with the latest release?
Not reproduced in the latest stable release (1.9.3), only in 1.10rc1
What did you do?
Run
go vet
on the following file:What did you expect to see?
No errors as file executes normally and prints
{{just field }}
.What did you see instead?
go vet
reportsPrintf format %s has arg ue of wrong type main.unexportedError
.As
fmt
package doc states,Error
method ofe
field cannot be used, ase
is unexported. In this case,fmt
just prints fields.As far as I can see in
go vet
source code, it reports error if field hasError
method but it is unexported. But the fact thate
can be printed withoutError()
method invocation is not taken into account.The text was updated successfully, but these errors were encountered: