From 1ee053e2742eab67234c06d73415d9510f1a530a Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Sat, 10 May 2025 20:01:15 +0300 Subject: [PATCH 1/2] hash/maphash: hash channels in purego version too Make maphash properly hash channels as represented by pointer. Fixes #73657 --- src/hash/maphash/maphash_purego.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hash/maphash/maphash_purego.go b/src/hash/maphash/maphash_purego.go index 53636a48ca21c9..07b5eaa46056ac 100644 --- a/src/hash/maphash/maphash_purego.go +++ b/src/hash/maphash/maphash_purego.go @@ -161,7 +161,7 @@ func appendT(h *Hash, v reflect.Value) { case reflect.Bool: h.WriteByte(btoi(v.Bool())) return - case reflect.UnsafePointer, reflect.Pointer: + case reflect.UnsafePointer, reflect.Pointer, reflect.Chan: var buf [8]byte // because pointing to the abi.Escape call in comparableReady, // So this is ok to hash pointer, From 2537216a1e4e62791c7e417441ee770ca149f38a Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Sat, 10 May 2025 20:21:51 +0300 Subject: [PATCH 2/2] hash/maphash: more testcases for maphash.Comparable This commit extends test suite for maphash.Comparable in order to have at least some instances of pointer types. --- src/hash/maphash/maphash_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hash/maphash/maphash_test.go b/src/hash/maphash/maphash_test.go index 0774c1c3ced7c0..c9ef1777ec92f3 100644 --- a/src/hash/maphash/maphash_test.go +++ b/src/hash/maphash/maphash_test.go @@ -254,12 +254,17 @@ func TestComparable(t *testing.T) { } testComparable(t, s1, s2) testComparable(t, s1.s, s2.s) + c1 := make(chan struct{}) + c2 := make(chan struct{}) + testComparable(t, c1, c1) + testComparable(t, chan struct{}(nil)) testComparable(t, float32(0), negativeZero[float32]()) testComparable(t, float64(0), negativeZero[float64]()) testComparableNoEqual(t, math.NaN(), math.NaN()) testComparableNoEqual(t, [2]string{"a", ""}, [2]string{"", "a"}) testComparableNoEqual(t, struct{ a, b string }{"foo", ""}, struct{ a, b string }{"", "foo"}) testComparableNoEqual(t, struct{ a, b any }{int(0), struct{}{}}, struct{ a, b any }{struct{}{}, int(0)}) + testComparableNoEqual(t, c1, c2) } func testComparableNoEqual[T comparable](t *testing.T, v1, v2 T) {