diff options
author | Rob Pike <r@golang.org> | 2010-06-14 17:16:35 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2010-06-14 17:16:35 -0700 |
commit | 9f697f87517acf0d128dd5e63f46bf923799a490 (patch) | |
tree | eccd648cb983eb5bfb908be42e4a23364f30d2b9 /test | |
parent | 5f7cdead0c43a351ac3b82fc941bcd8ee50f27ef (diff) | |
download | go-9f697f87517acf0d128dd5e63f46bf923799a490.tar.gz |
fmt.Print*: reimplement to switch on type first.
This shortens, simplifies and regularizes the code significantly.
(Improvements to reflect could make another step.)
Passes all.bash.
One semantic change occurs: The String() method changes
behavior. It used to run only for string formats such as %s and %q.
Instead, it now runs whenever the item has the method and the
result is then processed by the format as a string. Besides the
regularization, this has three effects:
1) width is honored for String() items
2) %x works for String() items
3) implementations of String that merely recur will recur forever
Regarding point 3, example from the updated documentation:
type X int
func (x X) String() string { return Sprintf("%d", x) }
should cast the value before recurring:
func (x X) String() string { return Sprintf("%d", int(x)) }
R=rsc
CC=golang-dev
http://codereview.appspot.com/1613045
Diffstat (limited to 'test')
-rw-r--r-- | test/const3.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/test/const3.go b/test/const3.go index d49df2b88..dd5c88958 100644 --- a/test/const3.go +++ b/test/const3.go @@ -10,7 +10,7 @@ import "fmt" type T int -func (t T) String() string { return fmt.Sprintf("T%d", t) } +func (t T) String() string { return fmt.Sprintf("T%d", int(t)) } const ( A T = 1 << (1 << iota) |