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

ZeroNil has no effect on int pointers #45

@andersarpi

Description

@andersarpi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions