From 8cf7871c2699257e0d2cda34172c64cb31561cf1 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 20 May 2020 17:53:01 +0300 Subject: [PATCH] compiler: support nested slice element assignment --- pkg/compiler/codegen.go | 3 +-- pkg/compiler/slice_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 793181b94..cdb7a0ab5 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -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) diff --git a/pkg/compiler/slice_test.go b/pkg/compiler/slice_test.go index af7d07f80..326fe0e72 100644 --- a/pkg/compiler/slice_test.go +++ b/pkg/compiler/slice_test.go @@ -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) {