aboutsummaryrefslogtreecommitdiff
path: root/test/const3.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2010-06-14 17:16:35 -0700
committerRob Pike <r@golang.org>2010-06-14 17:16:35 -0700
commitd482c163be5ef83b9a4ff5b1f366ceb6cfff6ed7 (patch)
treecd5819c95c79ba75273a44cefce075b84966312a /test/const3.go
parent43b3a247d3471507da5df1f144ef12bda303dfe0 (diff)
downloadgo-d482c163be5ef83b9a4ff5b1f366ceb6cfff6ed7.tar.gz
go-d482c163be5ef83b9a4ff5b1f366ceb6cfff6ed7.zip
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 https://golang.org/cl/1613045
Diffstat (limited to 'test/const3.go')
-rw-r--r--test/const3.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/test/const3.go b/test/const3.go
index d49df2b88f..dd5c88958d 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)