From 0b78d9d2152872a899a1724ca078634598ea272f Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 30 Jan 2024 15:10:55 -0800 Subject: [PATCH 1/3] no need to use explicit base type to retrieve array value element --- gnovm/pkg/gnolang/values.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 53d482613a1..323f5f2f0cf 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -2533,7 +2533,7 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { cv.Base = base switch cb := base.(type) { case *ArrayValue: - et := baseOf(tv.T).(*ArrayType).Elt + et := baseOf(tv.T).Elem() epv := cb.GetPointerAtIndexInt2(store, cv.Index, et) cv.TV = epv.TV // TODO optimize? (epv.* ignored) case *StructValue: From 0a25fa962ad97052c2d4bbf6dff7f69d73e63273 Mon Sep 17 00:00:00 2001 From: deelawn Date: Tue, 30 Jan 2024 16:41:20 -0800 Subject: [PATCH 2/3] added test --- .../cmd/gnoland/testdata/issue-1588.txtar | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 gno.land/cmd/gnoland/testdata/issue-1588.txtar diff --git a/gno.land/cmd/gnoland/testdata/issue-1588.txtar b/gno.land/cmd/gnoland/testdata/issue-1588.txtar new file mode 100644 index 00000000000..dc2467ca75e --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/issue-1588.txtar @@ -0,0 +1,48 @@ +# Reproducible Test for https://github.com/gnolang/gno/issues/1588 + +gnoland start + +# add contract +gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/demo/xx -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout OK! + +gnokey maketx call -pkgpath gno.land/r/demo/xx -func DefineFamily -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout OK! + +gnokey maketx call -pkgpath gno.land/r/demo/xx -func GetOutcastChildAge -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout OK! +stdout '(10 int)' + +-- gno.mod -- +module gno.land/r/demo/xx + +-- realm.gno -- +package xx + +type Parent struct { + children []Child + outcastChild *Child +} + +type Child struct { + age int +} + +var parent Parent + +func DefineFamily() { + parent = Parent{ + children: []Child{ + {age: 10}, + {age: 20}, + }, + } + parent.outcastChild = &parent.children[0] +} + +func GetOutcastChildAge() int { + if parent.outcastChild == nil { + return -1 + } + return parent.outcastChild.age +} From 70bf9d26fcb4189457f6f00fee334e0d5da655f3 Mon Sep 17 00:00:00 2001 From: deelawn Date: Wed, 21 Feb 2024 09:59:13 -0800 Subject: [PATCH 3/3] do pointertype type assertion --- gnovm/pkg/gnolang/values.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index 323f5f2f0cf..85e6562eca6 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -2533,7 +2533,7 @@ func fillValueTV(store Store, tv *TypedValue) *TypedValue { cv.Base = base switch cb := base.(type) { case *ArrayValue: - et := baseOf(tv.T).Elem() + et := baseOf(tv.T).(*PointerType).Elt epv := cb.GetPointerAtIndexInt2(store, cv.Index, et) cv.TV = epv.TV // TODO optimize? (epv.* ignored) case *StructValue: