aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2017-11-22 18:21:39 +0000
committerDaniel Martí <mvdan@mvdan.cc>2017-11-22 20:27:00 +0000
commit88599f184d686339954482d1be067d44b2efb644 (patch)
tree589e1b7151861b55b24fe572da2f21a2c18f9e28 /src
parent1490cf67edc42ffd2abd6230f0caebebaf832a96 (diff)
downloadgo-88599f184d686339954482d1be067d44b2efb644.tar.xz
cmd/vet: add missing %v to the verb regex
In golang.org/cl/74352, the print rules were overhauled to give better error messages. This also meant adding a regex to find and extract the used formatting verbs. However, %v was missed. Add it to the expression, and add a test too. Fixes #22847. Change-Id: If117cc364db0cb91373742239b8a626c137642b0 Reviewed-on: https://go-review.googlesource.com/79455 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/vet/print.go2
-rw-r--r--src/cmd/vet/testdata/print.go1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/cmd/vet/print.go b/src/cmd/vet/print.go
index e10c3169b3..beb78030ef 100644
--- a/src/cmd/vet/print.go
+++ b/src/cmd/vet/print.go
@@ -614,7 +614,7 @@ const (
flagsRE = `[+\-#]*`
indexOptRE = `(\[[0-9]+\])?`
numOptRE = `([0-9]+|` + indexOptRE + `\*)?`
- verbRE = `[bcdefgopqstxEFGUX]`
+ verbRE = `[bcdefgopqstvxEFGUX]`
)
// checkPrint checks a call to an unformatted print routine such as Println.
diff --git a/src/cmd/vet/testdata/print.go b/src/cmd/vet/testdata/print.go
index db11e125ae..abb926abf7 100644
--- a/src/cmd/vet/testdata/print.go
+++ b/src/cmd/vet/testdata/print.go
@@ -141,6 +141,7 @@ func PrintfTests() {
fmt.Printf("%.*s %d %6g", 3, "hi", 23, 'x') // ERROR "Printf format %6g has arg 'x' of wrong type rune"
fmt.Println() // not an error
fmt.Println("%s", "hi") // ERROR "Println call has possible formatting directive %s"
+ fmt.Println("%v", "hi") // ERROR "Println call has possible formatting directive %v"
fmt.Println("0.0%") // correct (trailing % couldn't be a formatting directive)
fmt.Printf("%s", "hi", 3) // ERROR "Printf call needs 1 arg but has 2 args"
_ = fmt.Sprintf("%"+("s"), "hi", 3) // ERROR "Sprintf call needs 1 arg but has 2 args"