Skip to content

Commit

Permalink
Merge pull request #88 from vvakame/fix-typed-nil
Browse files Browse the repository at this point in the history
handle typed nil on field
  • Loading branch information
pohly authored Sep 7, 2021
2 parents 5e3dfaa + 014a2c3 commit 59f2313
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 59f2313

Please sign in to comment.