Skip to content

hash/maphash: hash channels in purego version of maphash.Comparable #73660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hash/maphash/maphash_purego.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/hash/maphash/maphash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down