From 04252eccb9d565ac559eee6a62be04f927675aab Mon Sep 17 00:00:00 2001 From: Caleb Spare Date: Fri, 18 Oct 2019 12:58:47 -0700 Subject: [PATCH] go/analysis/passes/printf: allow %x/%X for float/complex types These verbs are supported as of Go 1.13. Updates golang/go#34993 Change-Id: Ib7892e45b51073e3771bebb652a8fe3a1c6ae3c6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/202041 Run-TryBot: Caleb Spare Reviewed-by: Alan Donovan --- go/analysis/passes/printf/printf.go | 4 ++-- go/analysis/passes/printf/testdata/src/a/a.go | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/go/analysis/passes/printf/printf.go b/go/analysis/passes/printf/printf.go index f0d7e44c651..b5015380551 100644 --- a/go/analysis/passes/printf/printf.go +++ b/go/analysis/passes/printf/printf.go @@ -766,8 +766,8 @@ var printVerbs = []printVerb{ {'U', "-#", argRune | argInt}, {'v', allFlags, anyType}, {'w', allFlags, argError}, - {'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, diff --git a/go/analysis/passes/printf/testdata/src/a/a.go b/go/analysis/passes/printf/testdata/src/a/a.go index 69951760ef6..49cba6c6170 100644 --- a/go/analysis/passes/printf/testdata/src/a/a.go +++ b/go/analysis/passes/printf/testdata/src/a/a.go @@ -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) @@ -128,7 +128,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"