Skip to content

Commit f79703f

Browse files
deelawnjaekwon
authored andcommitted
handle additional append cases
1 parent fcd8249 commit f79703f

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

gno.land/cmd/gnoland/testdata/append.txtar

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ stdout OK!
88
gnokey maketx call -pkgpath gno.land/r/append -func Append -gas-fee 1000000ugnot -gas-wanted 2000000 -args '1' -broadcast -chainid=tendermint_test test1
99
stdout OK!
1010

11+
gnokey maketx call -pkgpath gno.land/r/append -func AppendNil -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
12+
stdout OK!
13+
1114
# Call Append 2
1215
gnokey maketx call -pkgpath gno.land/r/append -func Append -gas-fee 1000000ugnot -gas-wanted 2000000 -args '2' -broadcast -chainid=tendermint_test test1
1316
stdout OK!
@@ -60,6 +63,10 @@ gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot
6063
stdout '("2-3-42-70-100-" string)'
6164
stdout OK!
6265

66+
gnokey maketx call -pkgpath gno.land/r/append -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args 'd' -broadcast -chainid=tendermint_test test1
67+
stdout '("1-" string)'
68+
stdout OK!
69+
6370
-- append.gno --
6471
package append
6572

@@ -69,7 +76,7 @@ import (
6976

7077
type T struct{ i int }
7178

72-
var a, b []T
79+
var a, b, d []T
7380
var c = []T{{i: 100}}
7481

7582

@@ -104,10 +111,19 @@ func ReassignC() {
104111
c[0] = T{i: 200}
105112
}
106113

114+
func AppendNil() {
115+
d = append(d, a...)
116+
}
117+
107118
func Render(path string) string {
119+
source := a
120+
if path == "d" {
121+
source = d
122+
}
123+
108124
var s string
109-
for i:=0;i<len(a);i++{
110-
s+=ufmt.Sprintf("%d-", a[i].i)
125+
for i:=0;i<len(source);i++{
126+
s+=ufmt.Sprintf("%d-", source[i].i)
111127
}
112128
return s
113129
}

gnovm/pkg/gnolang/uverse.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ func UverseNode() *PackageNode {
210210
// append(nil, *SliceValue) new list ---------
211211
list := make([]TypedValue, argsl)
212212
if 0 < argsl {
213-
copy(
214-
list[:argsl],
215-
argsb.List[argso:argso+argsl])
213+
for i := 0; i < argsl; i++ {
214+
list[i] = argsb.List[argso+i].DeepCopy(m.Alloc, m.Store)
215+
}
216216
}
217217
m.PushValue(TypedValue{
218218
T: xt,
@@ -469,11 +469,12 @@ func UverseNode() *PackageNode {
469469
return
470470
} else {
471471
// append(*SliceValue, *NativeValue) new list --------
472-
list := make([]TypedValue, xvl+argsl)
472+
listLen := xvl + argsl
473+
list := make([]TypedValue, listLen)
473474
if 0 < xvl {
474-
copy(
475-
list[:xvl],
476-
xvb.List[xvo:xvo+xvl])
475+
for i := 0; i < listLen; i++ {
476+
list[i] = xvb.List[xvo+i].DeepCopy(m.Alloc, m.Store)
477+
}
477478
}
478479
if 0 < argsl {
479480
copyNativeToList(

0 commit comments

Comments
 (0)