Skip to content

Commit

Permalink
fix(#2041):cannot use struct as key of a map
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed May 6, 2024
1 parent c66adb2 commit b5f52b3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -1541,10 +1541,10 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey {
sv := tv.V.(*StructValue)
sl := len(sv.Fields)
bz = append(bz, '{')
bzl := FieldTypeList(bt.Fields).Types()
for i := 0; i < sl; i++ {
fv := fillValueTV(store, &sv.Fields[i])
ft := bt.Fields[i]
omitTypes := ft.Elem().Kind() != InterfaceKind
omitTypes := bzl[i].Kind() != InterfaceKind
bz = append(bz, fv.ComputeMapKey(store, omitTypes)...)
if i != sl-1 {
bz = append(bz, ',')
Expand Down
23 changes: 23 additions & 0 deletions gnovm/tests/files/struct58.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

type I interface {
dummy()
}
type IS struct{}

func (iss IS) dummy() {
}

type S struct {
x int
I
}

func main() {
m := make(map[S]string)
m[S{0, IS{}}] = "test"
println(m)
}

// Output:
// map{(struct{(0 int),(struct{} main.IS)} main.S):("test" string)}

0 comments on commit b5f52b3

Please sign in to comment.