Skip to content

Commit 991d59a

Browse files
michael-schallerdmitshur
authored andcommitted
[release-branch.go1.13] 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. For golang/go#39287. 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]> Reviewed-on: https://go-review.googlesource.com/c/tools/+/237945 Run-TryBot: Dmitri Shuralyov <[email protected]>
1 parent f713011 commit 991d59a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

go/analysis/passes/printf/printf.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ var printVerbs = []printVerb{
732732
{'g', sharpNumFlag, argFloat | argComplex},
733733
{'G', sharpNumFlag, argFloat | argComplex},
734734
{'o', sharpNumFlag, argInt | argPointer},
735+
{'O', sharpNumFlag, argInt | argPointer},
735736
{'p', "-#", argPointer},
736737
{'q', " -+.0#", argRune | argInt | argString},
737738
{'s', " -+.0", argString},

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

Lines changed: 10 additions & 2 deletions
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"
@@ -736,19 +738,21 @@ func PointerVerbs() {
736738
chan_ := make(chan bool)
737739
func_ := func(bool) {}
738740

739-
// %p, %b, %d, %o, %x, and %X all support pointers.
741+
// %p, %b, %d, %o, %O, %x, and %X all support pointers.
740742
fmt.Printf("%p", ptr)
741743
fmt.Printf("%b", ptr)
742744
fmt.Printf("%d", ptr)
743745
fmt.Printf("%o", ptr)
746+
fmt.Printf("%O", ptr)
744747
fmt.Printf("%x", ptr)
745748
fmt.Printf("%X", ptr)
746749

747-
// %p, %b, %d, %o, %x, and %X all support channels.
750+
// %p, %b, %d, %o, %O, %x, and %X all support channels.
748751
fmt.Printf("%p", chan_)
749752
fmt.Printf("%b", chan_)
750753
fmt.Printf("%d", chan_)
751754
fmt.Printf("%o", chan_)
755+
fmt.Printf("%O", chan_)
752756
fmt.Printf("%x", chan_)
753757
fmt.Printf("%X", chan_)
754758

@@ -757,6 +761,7 @@ func PointerVerbs() {
757761
fmt.Printf("%b", func_) // want `Printf format %b arg func_ is a func value, not called`
758762
fmt.Printf("%d", func_) // want `Printf format %d arg func_ is a func value, not called`
759763
fmt.Printf("%o", func_) // want `Printf format %o arg func_ is a func value, not called`
764+
fmt.Printf("%O", func_) // want `Printf format %O arg func_ is a func value, not called`
760765
fmt.Printf("%x", func_) // want `Printf format %x arg func_ is a func value, not called`
761766
fmt.Printf("%X", func_) // want `Printf format %X arg func_ is a func value, not called`
762767

@@ -768,6 +773,7 @@ func PointerVerbs() {
768773
fmt.Printf("%d", slice) // want `Printf format %d has arg slice of wrong type \[\]bool`
769774

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

772778
fmt.Printf("%x", slice) // want `Printf format %x has arg slice of wrong type \[\]bool`
773779
fmt.Printf("%X", slice) // want `Printf format %X has arg slice of wrong type \[\]bool`
@@ -777,6 +783,7 @@ func PointerVerbs() {
777783
fmt.Printf("%b", array) // want `Printf format %b has arg array of wrong type \[3\]bool`
778784
fmt.Printf("%d", array) // want `Printf format %d has arg array of wrong type \[3\]bool`
779785
fmt.Printf("%o", array) // want `Printf format %o has arg array of wrong type \[3\]bool`
786+
fmt.Printf("%O", array) // want `Printf format %O has arg array of wrong type \[3\]bool`
780787
fmt.Printf("%x", array) // want `Printf format %x has arg array of wrong type \[3\]bool`
781788
fmt.Printf("%X", array) // want `Printf format %X has arg array of wrong type \[3\]bool`
782789

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

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

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

0 commit comments

Comments
 (0)