diff options
author | Damian Gryski <[email protected]> | 2023-02-24 23:48:31 -0800 |
---|---|---|
committer | Ayke <[email protected]> | 2023-02-25 06:42:30 -0800 |
commit | 7b44fcd865370d5ecf7471b04ad1b4e013e63708 (patch) | |
tree | c979a2b3e51fcdd565f9a3bdb0ba92372c561696 /testdata/map.go | |
parent | cfe971d723a4e91e7f7df65c8f9479e4eb2c7477 (diff) | |
download | tinygo-7b44fcd865370d5ecf7471b04ad1b4e013e63708.tar.gz tinygo-7b44fcd865370d5ecf7471b04ad1b4e013e63708.zip |
runtime: properly turn pointer into empty interface when hashing
Diffstat (limited to 'testdata/map.go')
-rw-r--r-- | testdata/map.go | 34 |
1 files changed, 34 insertions, 0 deletions
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") + } +} |