-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: make printf checking more precise when arguments are changed #26555
Comments
Change https://golang.org/cl/125039 mentions this issue: |
Fixes #26486 Updates #26555 Change-Id: I402137b796e574e9b085ab54290d1b4ef73d3fcc Reviewed-on: https://go-review.googlesource.com/125039 Reviewed-by: Russ Cox <rsc@golang.org>
It seems to me like this would require the use of more advanced tooling in vet, such as the use of |
I've seen an issue with the following code which now fails vet in v1.11: func Say(expected string, args ...interface{}) *sayMatcher {
formattedRegexp := expected
if len(args) > 0 {
formattedRegexp = fmt.Sprintf(expected, args...)
}
return &sayMatcher{
re: regexp.MustCompile(formattedRegexp),
}
} Re-writing like this allows it to pass vet, but this seems like a very fragile "fix". func Say(expected string, args ...interface{}) *sayMatcher {
if len(args) > 0 {
expected = fmt.Sprintf(expected, args...)
}
return &sayMatcher{
re: regexp.MustCompile(expected),
}
} Ideally |
- go vet in Go v1.11 identifies `Say()` as a print wrapper - go vet will then fail for `Say("%")` because this is not a valid Sprintf template - Because of golang/go#26486, changing the way that the functon is written will work around the vet issue - I have added a comment documenting that this is not ideal in golang/go#26555 (comment)
- go vet in Go v1.11 identifies `Say()` as a print wrapper - go vet will then fail for `Say("%")` because this is not a valid Sprintf template - Because of golang/go#26486, changing the way that the functon is written will work around the vet issue - I have added a comment documenting that this is not ideal in golang/go#26555 (comment)
For #26486 https://golang.org/cl/125039 changed the printf checking to only warn about functions that do not modify the arguments before passing them to
fmt.Printf
(or whatever). The example in that issue, drawn from real code, is:This can be called as
dbg("", err)
.The fix in CL 125039 means that we no longer issue printf warnings for functions like this:
We should figure out a way to continue issuing warnings for
Prefix
without issuing them fordbg
.The text was updated successfully, but these errors were encountered: