summaryrefslogtreecommitdiff
path: root/spew/format.go
diff options
context:
space:
mode:
authorDave Collins <[email protected]>2013-09-09 20:38:28 -0500
committerDave Collins <[email protected]>2013-09-09 20:38:28 -0500
commit7ea732c827c17c2e5cf8655aac42e3abe058ef17 (patch)
treee4c7c8a9c7545bc004fd6442b5f6dc0ff11bade5 /spew/format.go
parentdab6603c081108e15997eedd5def1a9344e63469 (diff)
Detect nil slices and print them as <nil>.
This commit modifies the code to detect nil slices and display them as <nil> (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.
Diffstat (limited to 'spew/format.go')
-rw-r--r--spew/format.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/spew/format.go b/spew/format.go
index f9b91ae..70785fa 100644
--- a/spew/format.go
+++ b/spew/format.go
@@ -256,7 +256,14 @@ func (f *formatState) format(v reflect.Value) {
case reflect.Complex128:
printComplex(f.fs, v.Complex(), 64)
- case reflect.Array, reflect.Slice:
+ case reflect.Slice:
+ if v.IsNil() {
+ f.fs.Write(nilAngleBytes)
+ break
+ }
+ fallthrough
+
+ case reflect.Array:
f.fs.Write(openBracketBytes)
f.depth++
if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) {