You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.
ref: http://play.golang.org/p/XEZS8bg0HJ
Given a type T with an underlying integer type, define a String method on T and use
fmt.Sprintf with one of the integer verbs to returns a string.
What happened?
It works just fine for the following integer verbs:
'b', 'c', 'd', 'o' and 'U'
but it doesn't work for any of the following integer verbs:
'q', 'x' and 'X'
This is because the verbs 'q', 'x' and 'X' are also valid string verbs; which have
special treatment.
Ref: http://golang.org/src/pkg/fmt/print.go#L678
What should have happened instead?
It should work for all integer verbs, if the underlying type is an integer and not a
string.
Please provide any additional information below.
go version devel +9562b65a3c51 Wed Jul 16 20:48:57 2014 +1000 linux/amd64
The text was updated successfully, but these errors were encountered:
This is already a somewhat regular occurrence when having a type T string that
implements the error interface and needs to print itself, in which case the accepted
solution is to add a type conversion to the underlying type.
So in this case return fmt.Sprintf("%q", int(t))
Types in Go convey method sets -- If you don't want your type to have a certain method
set (in this case one that includes the String method), convert it to a different type
that has the same underlying type but a different method set.
The text was updated successfully, but these errors were encountered: