Skip to content

Commit

Permalink
fix(gnolang): fix panic when using struct as index of map (#2044)
Browse files Browse the repository at this point in the history
Closes #2041. Use fieldlist to get field type
<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [ ] Added new tests, or not needed, or not feasible
- [ ] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
  • Loading branch information
omarsy authored May 9, 2024
1 parent 8057505 commit 711f4d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions gnovm/pkg/gnolang/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -1543,8 +1543,7 @@ func (tv *TypedValue) ComputeMapKey(store Store, omitType bool) MapKey {
bz = append(bz, '{')
for i := 0; i < sl; i++ {
fv := fillValueTV(store, &sv.Fields[i])
ft := bt.Fields[i]
omitTypes := ft.Elem().Kind() != InterfaceKind
omitTypes := bt.Fields[i].Type.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 711f4d0

Please sign in to comment.