mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 23:33:37 +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 {
|
if !isAssignOp {
|
||||||
ast.Walk(c, n.Rhs[i])
|
ast.Walk(c, n.Rhs[i])
|
||||||
}
|
}
|
||||||
name := t.X.(*ast.Ident).Name
|
ast.Walk(c, t.X)
|
||||||
c.emitLoadVar(name)
|
|
||||||
ast.Walk(c, t.Index)
|
ast.Walk(c, t.Index)
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.ROT)
|
emit.Opcode(c.prog.BinWriter, opcode.ROT)
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.SETITEM)
|
emit.Opcode(c.prog.BinWriter, opcode.SETITEM)
|
||||||
|
|
|
@ -212,6 +212,16 @@ var sliceTestCases = []testCase{
|
||||||
}`,
|
}`,
|
||||||
[]byte{1, 2},
|
[]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) {
|
func TestSliceOperations(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue