I thought I'd have a look into this and it seems that a fairly minor
change fixes the fault.
diff -r 073d912321cc src/pkg/fmt/print.go
--- a/src/pkg/fmt/print.go Tue Jan 22 03:18:20 2013 +0800
+++ b/src/pkg/fmt/print.go Wed Jan 23 09:34:15 2013 +1030
@@ -939,7 +939,7 @@
}
case reflect.Array, reflect.Slice:
// Byte slices are special.
- if f.Type().Elem().Kind() == reflect.Uint8 {
+ if f.Type().Elem() == reflect.TypeOf(byte(0)) {
// We know it's a slice of bytes, but we also know it does not have static type
// []byte, or it would have been caught above. Therefore we cannot convert
// it directly in the (slightly) obvious way: f.Interface().([]byte); it doesn't have
Running the code at
http://play.golang.org/p/mj_DExS5ag with this change
gives:
$ go run test.go
[]main.A []main.A{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
[]uint8 []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
[10]main.A [10]main.A{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
[10]main.B [10]main.B{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Which looks like what is probably intended. I'm concerned about the
repeated calls to reflect.TypeOf() though. Is there an exported value
that is like reflect.Uint8, but is a reflect.Type rather than a
reflect.Kind? Or would a fmt pkg variable be worth declaring for this
use? Or just deal with it?
./all.bash passes all tests with this change at tip.
I'm happy to put together the tests and a CL for this if I can be given
minor direction on this particular bit of the issue.
thanks
Dan
On Tue, 2013-01-22 at 15:02 +1030, Dan Kortschak wrote:
Issue submitted: golang.org/issue/4685
--