diff --git a/gno.land/cmd/gnoland/testdata/pr-1112.txtar b/gno.land/cmd/gnoland/testdata/pr-1112.txtar new file mode 100644 index 00000000000..128bb48e1aa --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/pr-1112.txtar @@ -0,0 +1,35 @@ +# Test for https://github.com/gnolang/gno/pull/1112 + +gnoland start + +# add contract +gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/demo/mapindex -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout OK! + +# call map +gnokey maketx call -pkgpath gno.land/r/demo/mapindex -func FindMapWithKey -args 3 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout OK! +stdout '"three" string' + +# XXX without patching realm.go, expected stdout is +# stdout ' string' + + +-- gno.mod -- +module gno.land/r/demo/mapindex + + +-- realm.gno -- +package mapindex + +var mapus map[uint64]string = make(map[uint64]string) + +func init() { + mapus[3] = "three" + mapus[5] = "five" + mapus[9] = "nine" +} + +func FindMapWithKey(k uint64) string { + return mapus[k] +} \ No newline at end of file diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index d146b3fa7db..39fe8546c3d 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -1356,6 +1356,8 @@ func fillTypesOfValue(store Store, val Value) Value { for cur := cv.List.Head; cur != nil; cur = cur.Next { fillTypesTV(store, &cur.Key) fillTypesTV(store, &cur.Value) + + cv.vmap[cur.Key.ComputeMapKey(store, false)] = cur } return cv case TypeValue: