diff --git a/dumper.go b/dumper.go index 45968c1..b92d47e 100644 --- a/dumper.go +++ b/dumper.go @@ -240,22 +240,26 @@ func (d *Dumper) dump(val reflect.Value, ignoreDepth ...bool) { } func (d *Dumper) dumpSlice(v reflect.Value) { - length := v.Len() - var tag string if d.ptrTag != 0 { tag = __(d.Theme.PointerTag, fmt.Sprintf("#%d", d.ptrTag)) d.ptrTag = 0 } - if v.IsNil() { + length := v.Len() + + if v.Kind() == reflect.Slice { + if v.IsNil() { + d.buf.WriteString(__(d.Theme.Types, v.Type().String())) + d.writeNil() + d.buf.WriteString(tag) + return + } + d.buf.WriteString(__(d.Theme.Types, fmt.Sprintf("%s:%d:%d", v.Type(), length, v.Cap()))) + } else { d.buf.WriteString(__(d.Theme.Types, v.Type().String())) - d.writeNil() - d.buf.WriteString(tag) - return } - d.buf.WriteString(__(d.Theme.Types, fmt.Sprintf("%s:%d:%d", v.Type(), length, v.Cap()))) d.buf.WriteString(__(d.Theme.Braces, fmt.Sprintf(" {%s", tag))) d.depth++ diff --git a/dumper_test.go b/dumper_test.go index af016b9..c77f813 100644 --- a/dumper_test.go +++ b/dumper_test.go @@ -729,6 +729,7 @@ func TestCanDumpSlices(t *testing.T) { type Slice []any var nilSlice []Slice + var zeroArray [2]any foo := "foo" bar := "bar" @@ -752,6 +753,8 @@ func TestCanDumpSlices(t *testing.T) { }, make([]any, 3, 8), nilSlice, + [2]int{1, 2}, + zeroArray, } s = append(s, &s) diff --git a/testdata/slices.txt b/testdata/slices.txt index a337c74..f4faead 100644 --- a/testdata/slices.txt +++ b/testdata/slices.txt @@ -1,4 +1,4 @@ -godump_test.Slice:11:20 { +godump_test.Slice:13:24 { 1, 2.3, true, @@ -20,7 +20,15 @@ godump_test.Slice:11:20 { nil, }, []godump_test.Slice(nil), - &godump_test.Slice:11:20 {#2 + [2]int { + 1, + 2, + }, + [2]interface {} { + nil, + nil, + }, + &godump_test.Slice:13:24 {#2 1, 2.3, true, @@ -39,6 +47,14 @@ godump_test.Slice:11:20 { nil, }, []godump_test.Slice(nil), + [2]int { + 1, + 2, + }, + [2]interface {} { + nil, + nil, + }, &@2, }, } \ No newline at end of file