ZeroNil has no effect on int pointers
andersarpi opened this issue · 0 comments
andersarpi commented
I just ran into this issue, took some time to figure out.
type t struct {
A *int
}
var zero int
fmt.Println(hashstructure.Hash(t{}, hashstructure.FormatV2, nil))
fmt.Println(hashstructure.Hash(t{A: &zero}, hashstructure.FormatV2, nil))
opts := &hashstructure.HashOptions{ZeroNil: true}
fmt.Println(hashstructure.Hash(t{}, hashstructure.FormatV2, opts))
fmt.Println(hashstructure.Hash(t{A: &zero}, hashstructure.FormatV2, opts))
opts.ZeroNil = false
fmt.Println(hashstructure.Hash(t{}, hashstructure.FormatV2, opts))
fmt.Println(hashstructure.Hash(t{A: &zero}, hashstructure.FormatV2, opts))
The output from the code above is as follows, showing that the ZeroNil
option has no effect.
16677325619216437773 <nil>
16677325619216437773 <nil>
16677325619216437773 <nil>
16677325619216437773 <nil>
16677325619216437773 <nil>
16677325619216437773 <nil>
Note that for other types I tried (string
, bool
) the setting did seem to work correctly.