Skip to content

Commit

Permalink
[release-branch.go1.13] go/analysis/passes/printf: allow %x/%X for fl…
Browse files Browse the repository at this point in the history
…oat/complex types

These verbs are supported as of Go 1.13.

Updates golang/go#34993.
For golang/go#39287.

Change-Id: Ib7892e45b51073e3771bebb652a8fe3a1c6ae3c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202041
Run-TryBot: Caleb Spare <cespare@gmail.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit 04252ec)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237942
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
cespare authored and dmitshur committed Jun 15, 2020
1 parent 25a4f13 commit 03eb592
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go/analysis/passes/printf/printf.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ var printVerbs = []printVerb{
{'U', "-#", argRune | argInt},
{'v', allFlags, anyType},
{'w', noFlag, anyType},
{'x', sharpNumFlag, argRune | argInt | argString | argPointer},
{'X', sharpNumFlag, argRune | argInt | argString | argPointer},
{'x', sharpNumFlag, argRune | argInt | argString | argPointer | argFloat | argComplex},
{'X', sharpNumFlag, argRune | argInt | argString | argPointer | argFloat | argComplex},
}

// okPrintfArg compares the formatState to the arguments actually present,
Expand Down
5 changes: 2 additions & 3 deletions go/analysis/passes/printf/testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func PrintfTests() {
fmt.Printf("%T %T", 3, i)
fmt.Printf("%U %U", 3, i)
fmt.Printf("%v %v", 3, i)
fmt.Printf("%x %x %x %x", 3, i, "hi", s)
fmt.Printf("%X %X %X %X", 3, i, "hi", s)
fmt.Printf("%x %x %x %x %x %x %x", 3, i, "hi", s, x, c, fslice)
fmt.Printf("%X %X %X %X %X %X %X", 3, i, "hi", s, x, c, fslice)
fmt.Printf("%.*s %d %g", 3, "hi", 23, 2.3)
fmt.Printf("%s", &stringerv)
fmt.Printf("%v", &stringerv)
Expand Down Expand Up @@ -129,7 +129,6 @@ func PrintfTests() {
fmt.Printf("%t", 23) // want "Printf format %t has arg 23 of wrong type int"
fmt.Printf("%U", x) // want "Printf format %U has arg x of wrong type float64"
fmt.Printf("%x", nil) // want "Printf format %x has arg nil of wrong type untyped nil"
fmt.Printf("%X", 2.3) // want "Printf format %X has arg 2.3 of wrong type float64"
fmt.Printf("%s", stringerv) // want "Printf format %s has arg stringerv of wrong type a.ptrStringer"
fmt.Printf("%t", stringerv) // want "Printf format %t has arg stringerv of wrong type a.ptrStringer"
fmt.Printf("%s", embeddedStringerv) // want "Printf format %s has arg embeddedStringerv of wrong type a.embeddedStringer"
Expand Down

0 comments on commit 03eb592

Please sign in to comment.