From bb88c1659e5dbca97052572a57c72d55b00ec697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 6 Feb 2025 10:59:37 +0100 Subject: [PATCH] Add support for complex64/complex128 Support for complex64 was accidentally removed in 72666c84d299423e672e13f061a2ef9e7131a169, complex128 is new. Now with tests. --- hashstructure.go | 2 +- hashstructure_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hashstructure.go b/hashstructure.go index ad1081f..845be7d 100644 --- a/hashstructure.go +++ b/hashstructure.go @@ -196,7 +196,7 @@ func (w *walker) visit(v reflect.Value, opts *visitOpts) (uint64, error) { return w.hashDirect(v.Interface()) } - if v.CanFloat() { + if v.CanFloat() || v.CanComplex() { return w.hashDirect(v.Interface()) } diff --git a/hashstructure_test.go b/hashstructure_test.go index 6a5e186..f89e2a9 100644 --- a/hashstructure_test.go +++ b/hashstructure_test.go @@ -750,6 +750,14 @@ func TestHash_golden(t *testing.T) { In: float64(42), Expect: 12162027084228238918, }, + { + In: complex64(42), + Expect: 13187391128804187615, + }, + { + In: complex128(42), + Expect: 4635205179288363782, + }, { In: true, Expect: 12638153115695167454,