Fix incorrect val display on packed nil interfaces.
This was reported by shurcooL as issue #12.
This commit is contained in:
parent
ff59042e2e
commit
173295b96e
|
@ -262,7 +262,11 @@ func (d *dumpState) dump(v reflect.Value) {
|
||||||
d.w.Write([]byte(strconv.Quote(v.String())))
|
d.w.Write([]byte(strconv.Quote(v.String())))
|
||||||
|
|
||||||
case reflect.Interface:
|
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:
|
case reflect.Ptr:
|
||||||
// Do nothing. We should never get here since pointers have already
|
// Do nothing. We should never get here since pointers have already
|
||||||
|
|
|
@ -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
|
// This is useful for data types like structs, arrays, slices, and maps which
|
||||||
// can contain varying types packed inside an interface.
|
// can contain varying types packed inside an interface.
|
||||||
func (f *formatState) unpackValue(v reflect.Value) reflect.Value {
|
func (f *formatState) unpackValue(v reflect.Value) reflect.Value {
|
||||||
if v.Kind() == reflect.Interface && !v.IsNil() {
|
if v.Kind() == reflect.Interface {
|
||||||
f.ignoreNextType = false
|
f.ignoreNextType = false
|
||||||
|
if !v.IsNil() {
|
||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +278,11 @@ func (f *formatState) format(v reflect.Value) {
|
||||||
f.fs.Write([]byte(v.String()))
|
f.fs.Write([]byte(v.String()))
|
||||||
|
|
||||||
case reflect.Interface:
|
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:
|
case reflect.Ptr:
|
||||||
// Do nothing. We should never get here since pointers have already
|
// Do nothing. We should never get here since pointers have already
|
||||||
|
|
Loading…
Reference in New Issue