aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2023-02-24 23:48:31 -0800
committerAyke <[email protected]>2023-02-25 06:42:30 -0800
commit7b44fcd865370d5ecf7471b04ad1b4e013e63708 (patch)
treec979a2b3e51fcdd565f9a3bdb0ba92372c561696
parentcfe971d723a4e91e7f7df65c8f9479e4eb2c7477 (diff)
downloadtinygo-7b44fcd865370d5ecf7471b04ad1b4e013e63708.tar.gz
tinygo-7b44fcd865370d5ecf7471b04ad1b4e013e63708.zip
runtime: properly turn pointer into empty interface when hashing
-rw-r--r--src/runtime/hashmap.go2
-rw-r--r--testdata/map.go34
-rw-r--r--testdata/map.txt1
3 files changed, 36 insertions, 1 deletions
diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go
index 2db09f590..e00b223d4 100644
--- a/src/runtime/hashmap.go
+++ b/src/runtime/hashmap.go
@@ -563,7 +563,7 @@ func hashmapInterfaceHash(itf interface{}, seed uintptr) uint32 {
}
func hashmapInterfacePtrHash(iptr unsafe.Pointer, size uintptr, seed uintptr) uint32 {
- _i := *(*_interface)(iptr)
+ _i := *(*interface{})(iptr)
return hashmapInterfaceHash(_i, seed)
}
diff --git a/testdata/map.go b/testdata/map.go
index d30889910..d746cf9fc 100644
--- a/testdata/map.go
+++ b/testdata/map.go
@@ -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")
+ }
+}
diff --git a/testdata/map.txt b/testdata/map.txt
index 6bf04c80d..d5e553b1a 100644
--- a/testdata/map.txt
+++ b/testdata/map.txt
@@ -80,3 +80,4 @@ tested growing of a map
2
2
done
+no interface lookup failures