From 7ea732c827c17c2e5cf8655aac42e3abe058ef17 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Mon, 9 Sep 2013 20:38:28 -0500 Subject: Detect nil slices and print them as . This commit modifies the code to detect nil slices and display them as (as opposed to simply empty slices). For most instances a nil slice can be treated the same as an empty slice, but there is a difference and things like reflect.DeepEqual notice. This change makes it clear whether the type in question is a nil slice or an empty slice. --- spew/dump.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'spew/dump.go') diff --git a/spew/dump.go b/spew/dump.go index 8dd8ca9..831715c 100644 --- a/spew/dump.go +++ b/spew/dump.go @@ -245,7 +245,14 @@ func (d *dumpState) dump(v reflect.Value) { case reflect.Complex128: printComplex(d.w, v.Complex(), 64) - case reflect.Array, reflect.Slice: + case reflect.Slice: + if v.IsNil() { + d.w.Write(nilAngleBytes) + break + } + fallthrough + + case reflect.Array: d.w.Write(openBraceNewlineBytes) d.depth++ if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { -- cgit v1.2.3