Skip to content

Commit

Permalink
handle typed nil on field
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Sep 7, 2021
1 parent 5e3dfaa commit 014a2c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions funcr/funcr.go
Expand Up @@ -287,6 +287,9 @@ func prettyWithFlags(value interface{}, flags uint32) string {
buf.WriteRune('}')
return buf.String()
case reflect.Ptr, reflect.Interface:
if v.IsNil() {
return "null"
}
return pretty(v.Elem().Interface())
}
return fmt.Sprintf(`"<unhandled-%s>"`, t.Kind().String())
Expand Down
9 changes: 9 additions & 0 deletions funcr/funcr_test.go
Expand Up @@ -95,6 +95,15 @@ func TestPretty(t *testing.T) {
{"nine", "three"},
{"seven", "six"},
},
struct {
A *int
B *int
C interface{}
D interface{}
}{
B: ptrint(1),
D: interface{}(2),
},
}

for i, tc := range cases {
Expand Down

0 comments on commit 014a2c3

Please sign in to comment.