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
An alias of []byte cannot be printed with fmt.Printf("%x") when the alias is
the receiver of the function. This is demonstrated here:
http://play.golang.org/p/0sTP27XZa4
In go play, I get '[process took too long]', but on my local machine, the program
containing this code compiles fine, but I get a stack overflow error when running it.
If I cast the alias back to []byte it prints fine: http://play.golang.org/p/WOBMERNSV1
The text was updated successfully, but these errors were encountered:
This is documented and intended behaviour. Quoting http://golang.org/pkg/fmt:
If the format (which is implicitly %v for Println etc.) is valid for a string (%s %q %v
%x %X), the following two rules also apply:
1. If an operand implements the error interface, the Error method will be used to
convert the object to a string, which will then be formatted as required by the verb (if
any).
2. If an operand implements method String() string, that method will be used to convert
the object to a string, which will then be formatted as required by the verb (if any).
To avoid recursion in cases such as
type X string
func (x X) String() string { return Sprintf("<%s>", x) }
convert the value before recurring:
func (x X) String() string { return Sprintf("<%s>", string(x)) }
by charlieandrews.cwa:
The text was updated successfully, but these errors were encountered: