diff --git a/spew/dump.go b/spew/dump.go index 98a68f1..8dd8ca9 100644 --- a/spew/dump.go +++ b/spew/dump.go @@ -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 diff --git a/spew/format.go b/spew/format.go index fc1d3ae..f9b91ae 100644 --- a/spew/format.go +++ b/spew/format.go @@ -92,9 +92,11 @@ 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 - v = v.Elem() + 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