mitchellh/hashstructure

IgnoreZeroValue panics for structs containing a map

c3mb0 opened this issue · 0 comments

c3mb0 commented

Simple example:

package main

import (
	"hash/fnv"

	"github.com/mitchellh/hashstructure/v2"
)

type test struct {
	Field map[string]string
}

func main() {
	t := new(test)
	hashstructure.Hash(t, hashstructure.FormatV2, &hashstructure.HashOptions{
		Hasher:          fnv.New64(),
		IgnoreZeroValue: true,
	})
}

Output:

panic: runtime error: comparing uncomparable type map[string]string

goroutine 1 [running]:
github.com/mitchellh/hashstructure/v2.(*walker).visit(0xc000068ed0, 0x4b4460, 0xc00000e028, 0x16, 0x0, 0x1007f2a71c34418, 0x7f2a71c325d0, 0x0)
	/tmp/gopath678501233/pkg/mod/github.com/mitchellh/hashstructure/v2@v2.0.1/hashstructure.go:327 +0x1145
github.com/mitchellh/hashstructure/v2.Hash(0x4b4460, 0xc00000e028, 0x2, 0xc000068f50, 0xc000034778, 0xc000068f78, 0x4056e5)
	/tmp/gopath678501233/pkg/mod/github.com/mitchellh/hashstructure/v2@v2.0.1/hashstructure.go:128 +0x1cb
main.main()
	/tmp/sandbox448559066/prog.go:15 +0xb6

Playground link

Is this an assumed behavior, or can something be done to prevent the panic?