runtime: properly turn pointer into empty interface when hashing

This commit is contained in:
Damian Gryski
2023-02-24 23:48:31 -08:00
committed by Ayke
parent cfe971d723
commit 7b44fcd865
3 changed files with 36 additions and 1 deletions
+34
View File
@@ -129,6 +129,8 @@ func main() {
floatcmplx()
mapgrow()
interfacerehash()
}
func floatcmplx() {
@@ -274,3 +276,35 @@ func mapgrow() {
}
println("done")
}
type Counter interface {
count() int
}
type counter struct {
i int
}
func (c *counter) count() int {
return c.i
}
func interfacerehash() {
m := make(map[Counter]int)
for i := 0; i < 20; i++ {
c := &counter{i}
m[c] = i
}
var failures int
for k, v := range m {
if got := m[k]; got != v {
println("lookup failure got", got, "want", v)
failures++
}
}
if failures == 0 {
println("no interface lookup failures")
}
}
+1
View File
@@ -80,3 +80,4 @@ tested growing of a map
2
2
done
no interface lookup failures