-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/vet: printfunc false negative on struct without String method #17798
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
I'll look into this and the #17057 on the weekend. |
FYI, it looks like the cl 28959 breaks printf check on err := errors.New("foobar")
fmt.Printf("%d", err) // vet silently skips this |
I think it would be better to fix these issues in go 1.8. |
CL 28959 doesn't change cmd/vet at all. It only changes cmd/vet/all, which is a script that runs cmd/vet over the standard library.
If the changes are fairly safe and we can get them in soon, I think that's fine. |
Btw, this is intentional. See #16314. |
This looks like a bug in package
In this case struct
type S [5]T
type S []T
type S map[string]T |
CL https://golang.org/cl/44831 mentions this issue. |
CL was marked as R=go1.10, so moving the issue milestone too. |
Change https://golang.org/cl/90516 mentions this issue: |
For example, the following program is valid: type T struct { f interface{} } func main() { fmt.Printf("%s", T{"foo"}) // prints {foo} } Since the field is of type interface{}, we might have any value in it. For example, if we had T{3}, fmt would complain. However, not knowing what the type under the interface is, we must be conservative. However, as shown in #17798, we should issue an error if the field's type is statically known to implement the error or fmt.Stringer interfaces. In those cases, the user likely wanted the %s format to call those methods. Keep the vet error in those cases. While at it, add more field type test cases, such as custom error types, and interfaces that extend the error interface. Fixes #23563. Change-Id: I063885955555917c59da000391b603f0d6dce432 Reviewed-on: https://go-review.googlesource.com/90516 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
$ go tool vet x.go $ go run x.go T {%!s(main.T=0)}
vet should know that S isn't a fmt.Stringer. The printfunc's "satisfies interface" check needs improvements. Related is #17057.
cc @robpike @valyala
The text was updated successfully, but these errors were encountered: