Fix incorrect val display on packed nil interfaces.

This was reported by shurcooL as issue #12.
This commit is contained in:
Dave Collins 2013-03-27 22:42:24 -05:00
parent ff59042e2e
commit 173295b96e
2 changed files with 14 additions and 4 deletions

View File

@ -262,7 +262,11 @@ func (d *dumpState) dump(v reflect.Value) {
d.w.Write([]byte(strconv.Quote(v.String())))
case reflect.Interface:
// Do nothing. We should never get here due to unpackValue calls.
// The only time we should get here is for nil interfaces due to
// unpackValue calls.
if v.IsNil() {
d.w.Write(nilAngleBytes)
}
case reflect.Ptr:
// Do nothing. We should never get here since pointers have already

View File

@ -92,10 +92,12 @@ func (f *formatState) constructOrigFormat(verb rune) (format string) {
// This is useful for data types like structs, arrays, slices, and maps which
// can contain varying types packed inside an interface.
func (f *formatState) unpackValue(v reflect.Value) reflect.Value {
if v.Kind() == reflect.Interface && !v.IsNil() {
if v.Kind() == reflect.Interface {
f.ignoreNextType = false
if !v.IsNil() {
v = v.Elem()
}
}
return v
}
@ -276,7 +278,11 @@ func (f *formatState) format(v reflect.Value) {
f.fs.Write([]byte(v.String()))
case reflect.Interface:
// Do nothing. We should never get here due to unpackValue calls
// The only time we should get here is for nil interfaces due to
// unpackValue calls.
if v.IsNil() {
f.fs.Write(nilAngleBytes)
}
case reflect.Ptr:
// Do nothing. We should never get here since pointers have already