Source file
test/fixedbugs/issue81299.go
1
2
3
4
5
6
7 package main
8
9 import (
10 "fmt"
11 "hash/maphash"
12 )
13
14 func main() {
15 testEmpty()
16 testNonEmpty()
17 }
18
19 func testEmpty() {
20 s := maphash.MakeSeed()
21 hashes := map[uint64]struct{}{}
22 addHash := func(x any) {
23 var h maphash.Hash
24 h.SetSeed(s)
25 var c maphash.ComparableHasher[any]
26 c.Hash(&h, x)
27 hashes[h.Sum64()] = struct{}{}
28 }
29 addHash(int64(0))
30 addHash(uint64(0))
31 addHash(int(0))
32 addHash(uint(0))
33 if len(hashes) < 3 {
34 panic(fmt.Sprintf("too few hashes %v\n", hashes))
35 }
36 }
37
38 type I interface {
39 foo()
40 }
41
42 type I1 int64
43 type I2 uint64
44 type I3 int
45 type I4 uint
46
47 func (i I1) foo() {}
48 func (i I2) foo() {}
49 func (i I3) foo() {}
50 func (i I4) foo() {}
51
52 func testNonEmpty() {
53 s := maphash.MakeSeed()
54 hashes := map[uint64]struct{}{}
55 addHash := func(x I) {
56 var h maphash.Hash
57 h.SetSeed(s)
58 var c maphash.ComparableHasher[I]
59 c.Hash(&h, x)
60 hashes[h.Sum64()] = struct{}{}
61 }
62 addHash(I1(0))
63 addHash(I2(0))
64 addHash(I3(0))
65 addHash(I4(0))
66 if len(hashes) < 3 {
67 panic(fmt.Sprintf("too few hashes %v\n", hashes))
68 }
69 }
70
View as plain text