mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
compiler: support nested slice element assignment
This commit is contained in:
parent
5b0e73ddf0
commit
8cf7871c26
2 changed files with 11 additions and 2 deletions
|
@ -432,8 +432,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
if !isAssignOp {
|
||||
ast.Walk(c, n.Rhs[i])
|
||||
}
|
||||
name := t.X.(*ast.Ident).Name
|
||||
c.emitLoadVar(name)
|
||||
ast.Walk(c, t.X)
|
||||
ast.Walk(c, t.Index)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.ROT)
|
||||
emit.Opcode(c.prog.BinWriter, opcode.SETITEM)
|
||||
|
|
|
@ -212,6 +212,16 @@ var sliceTestCases = []testCase{
|
|||
}`,
|
||||
[]byte{1, 2},
|
||||
},
|
||||
{
|
||||
"nested slice assignment",
|
||||
`package foo
|
||||
func Main() int {
|
||||
a := [][]int{[]int{1, 2}, []int{3, 4}}
|
||||
a[1][0] = 42
|
||||
return a[1][0]
|
||||
}`,
|
||||
big.NewInt(42),
|
||||
},
|
||||
}
|
||||
|
||||
func TestSliceOperations(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue