diff options
author | Rob Pike <r@golang.org> | 2018-01-30 13:49:48 +1100 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2018-01-30 04:26:07 +0000 |
commit | 8c1f21d9a2674dd9a410e0af94adf6fa7d2877d2 (patch) | |
tree | ae28c6b78fd5eeafd6d50c584f08eadf03751492 | |
parent | d529aa93ea64f234641d638c1bc7df5c568c474a (diff) | |
download | go-8c1f21d9a2674dd9a410e0af94adf6fa7d2877d2.tar.gz go-8c1f21d9a2674dd9a410e0af94adf6fa7d2877d2.zip |
cmd/vet: disable complaint about 0 flag in print
The problem is that vet complains about 0 as a Printf flag in some
situations where fmt allows it but probably shouldn't. The two
need to be brought in line, but it's too late in the release cycle.
The situation is messy and should be resolved properly in 1.11. This
CL is a simple fix to disable a spurious complaint for 1.10 that will be
resolved in a more thorough way in 1.11.
The workaround is just to be silent about flag 0, as suggested in
issue 23605.
Fixes #23605
Update #23498
Change-Id: Ice1a4f4d86845d70c1340a0a6430d74e5de9afd4
Reviewed-on: https://go-review.googlesource.com/90695
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
-rw-r--r-- | src/cmd/vet/print.go | 5 | ||||
-rw-r--r-- | src/cmd/vet/testdata/print.go | 6 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/cmd/vet/print.go b/src/cmd/vet/print.go index 456fbcc044..1c015913d5 100644 --- a/src/cmd/vet/print.go +++ b/src/cmd/vet/print.go @@ -569,6 +569,11 @@ func (f *File) okPrintfArg(call *ast.CallExpr, state *formatState) (ok bool) { return false } for _, flag := range state.flags { + // TODO: Disable complaint about '0' for Go 1.10. To be fixed properly in 1.11. + // See issues 23598 and 23605. + if flag == '0' { + continue + } if !strings.ContainsRune(v.flags, rune(flag)) { f.Badf(call.Pos(), "%s format %s has unrecognized flag %c", state.name, state.format, flag) return false diff --git a/src/cmd/vet/testdata/print.go b/src/cmd/vet/testdata/print.go index 55ab84fae7..6725bafadf 100644 --- a/src/cmd/vet/testdata/print.go +++ b/src/cmd/vet/testdata/print.go @@ -533,3 +533,9 @@ func UnexportedStringerOrError() { fmt.Println("foo\\n") // not an error fmt.Println(`foo\n`) // not an error } + +// TODO: Disable complaint about '0' for Go 1.10. To be fixed properly in 1.11. +// See issues 23598 and 23605. +func DisableErrorForFlag0() { + fmt.Printf("%0t", true) +} |