Skip to content

Commit 8b020ae

Browse files
michael-schallerianlancetaylor
authored andcommitted
go/analysis/passes/printf: allow %O in format strings
%O is supported since Go 1.13. See golang.org/design/19308-number-literals for the background. Support for %O has been added by copying and adapting the %o implementation. Updates golang/go#29986 Change-Id: Ic49d3cc8d9aefcc0ecbfcfe5ebf206e6f951d413 Reviewed-on: https://go-review.googlesource.com/c/tools/+/235100 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 253fce3 commit 8b020ae

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

go/analysis/passes/printf/printf.go

+1
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ var printVerbs = []printVerb{
805805
{'g', sharpNumFlag, argFloat | argComplex},
806806
{'G', sharpNumFlag, argFloat | argComplex},
807807
{'o', sharpNumFlag, argInt | argPointer},
808+
{'O', sharpNumFlag, argInt | argPointer},
808809
{'p', "-#", argPointer},
809810
{'q', " -+.0#", argRune | argInt | argString},
810811
{'s', " -+.0", argString},

go/analysis/passes/printf/testdata/src/a/a.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func PrintfTests() {
7777
fmt.Printf("%G %G %G %G", 3e9, x, fslice, c)
7878
fmt.Printf("%b %b %b %b", 3e9, x, fslice, c)
7979
fmt.Printf("%o %o", 3, i)
80+
fmt.Printf("%O %O", 3, i)
8081
fmt.Printf("%p", p)
8182
fmt.Printf("%q %q %q %q", 3, i, 'x', r)
8283
fmt.Printf("%s %s %s", "hi", s, []byte{65})
@@ -121,6 +122,7 @@ func PrintfTests() {
121122
fmt.Printf("%g", imap) // want `Printf format %g has arg imap of wrong type map\[int\]int`
122123
fmt.Printf("%G", i) // want "Printf format %G has arg i of wrong type int"
123124
fmt.Printf("%o", x) // want "Printf format %o has arg x of wrong type float64"
125+
fmt.Printf("%O", x) // want "Printf format %O has arg x of wrong type float64"
124126
fmt.Printf("%p", nil) // want "Printf format %p has arg nil of wrong type untyped nil"
125127
fmt.Printf("%p", 23) // want "Printf format %p has arg 23 of wrong type int"
126128
fmt.Printf("%q", x) // want "Printf format %q has arg x of wrong type float64"
@@ -799,19 +801,21 @@ func PointerVerbs() {
799801
chan_ := make(chan bool)
800802
func_ := func(bool) {}
801803

802-
// %p, %b, %d, %o, %x, and %X all support pointers.
804+
// %p, %b, %d, %o, %O, %x, and %X all support pointers.
803805
fmt.Printf("%p", ptr)
804806
fmt.Printf("%b", ptr)
805807
fmt.Printf("%d", ptr)
806808
fmt.Printf("%o", ptr)
809+
fmt.Printf("%O", ptr)
807810
fmt.Printf("%x", ptr)
808811
fmt.Printf("%X", ptr)
809812

810-
// %p, %b, %d, %o, %x, and %X all support channels.
813+
// %p, %b, %d, %o, %O, %x, and %X all support channels.
811814
fmt.Printf("%p", chan_)
812815
fmt.Printf("%b", chan_)
813816
fmt.Printf("%d", chan_)
814817
fmt.Printf("%o", chan_)
818+
fmt.Printf("%O", chan_)
815819
fmt.Printf("%x", chan_)
816820
fmt.Printf("%X", chan_)
817821

@@ -820,6 +824,7 @@ func PointerVerbs() {
820824
fmt.Printf("%b", func_) // want `Printf format %b arg func_ is a func value, not called`
821825
fmt.Printf("%d", func_) // want `Printf format %d arg func_ is a func value, not called`
822826
fmt.Printf("%o", func_) // want `Printf format %o arg func_ is a func value, not called`
827+
fmt.Printf("%O", func_) // want `Printf format %O arg func_ is a func value, not called`
823828
fmt.Printf("%x", func_) // want `Printf format %x arg func_ is a func value, not called`
824829
fmt.Printf("%X", func_) // want `Printf format %X arg func_ is a func value, not called`
825830

@@ -831,6 +836,7 @@ func PointerVerbs() {
831836
fmt.Printf("%d", slice) // want `Printf format %d has arg slice of wrong type \[\]bool`
832837

833838
fmt.Printf("%o", slice) // want `Printf format %o has arg slice of wrong type \[\]bool`
839+
fmt.Printf("%O", slice) // want `Printf format %O has arg slice of wrong type \[\]bool`
834840

835841
fmt.Printf("%x", slice) // want `Printf format %x has arg slice of wrong type \[\]bool`
836842
fmt.Printf("%X", slice) // want `Printf format %X has arg slice of wrong type \[\]bool`
@@ -840,6 +846,7 @@ func PointerVerbs() {
840846
fmt.Printf("%b", array) // want `Printf format %b has arg array of wrong type \[3\]bool`
841847
fmt.Printf("%d", array) // want `Printf format %d has arg array of wrong type \[3\]bool`
842848
fmt.Printf("%o", array) // want `Printf format %o has arg array of wrong type \[3\]bool`
849+
fmt.Printf("%O", array) // want `Printf format %O has arg array of wrong type \[3\]bool`
843850
fmt.Printf("%x", array) // want `Printf format %x has arg array of wrong type \[3\]bool`
844851
fmt.Printf("%X", array) // want `Printf format %X has arg array of wrong type \[3\]bool`
845852

@@ -850,6 +857,7 @@ func PointerVerbs() {
850857
fmt.Printf("%d", map_) // want `Printf format %d has arg map_ of wrong type map\[bool\]bool`
851858

852859
fmt.Printf("%o", map_) // want `Printf format %o has arg map_ of wrong type map\[bool\]bool`
860+
fmt.Printf("%O", map_) // want `Printf format %O has arg map_ of wrong type map\[bool\]bool`
853861

854862
fmt.Printf("%x", map_) // want `Printf format %x has arg map_ of wrong type map\[bool\]bool`
855863
fmt.Printf("%X", map_) // want `Printf format %X has arg map_ of wrong type map\[bool\]bool`

0 commit comments

Comments
 (0)