Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

ZeroNil has no effect on int pointers #45

Open
andersarpi opened this issue Feb 12, 2024 · 0 comments
Open

ZeroNil has no effect on int pointers #45

andersarpi opened this issue Feb 12, 2024 · 0 comments

Comments

@andersarpi
Copy link

andersarpi commented Feb 12, 2024

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant