From 5d578fdd95cce7208beeda34f3caac358b1b6e7d Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 27 Sep 2022 14:35:13 +0300 Subject: [PATCH] compiler: consider inlined types info on "append" handling We need to search for "append" argument type info not only inside local package type info map, but also inside the inlined type info map. Close #2696. --- pkg/compiler/codegen.go | 2 +- pkg/compiler/inline_test.go | 11 +++++++++++ pkg/compiler/testdata/inline/inline.go | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 1d56a2e2c..70e7592da 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -1819,7 +1819,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) { emit.Opcodes(c.prog.BinWriter, opcode.DROP, opcode.PUSH0) case "append": arg := expr.Args[0] - typ := c.typeInfo.Types[arg].Type + typ := c.typeOf(arg) ast.Walk(c, arg) emit.Opcodes(c.prog.BinWriter, opcode.DUP, opcode.ISNULL) if isByteSlice(typ) { diff --git a/pkg/compiler/inline_test.go b/pkg/compiler/inline_test.go index 9b217fa44..8a9dfdf24 100644 --- a/pkg/compiler/inline_test.go +++ b/pkg/compiler/inline_test.go @@ -432,3 +432,14 @@ func TestInlineDoubleConditionalReturn(t *testing.T) { }) } } + +func TestInlineAppendStatement(t *testing.T) { + src := `package foo + import "github.com/nspcc-dev/neo-go/pkg/compiler/testdata/inline" + + func Main() []byte { + val := []byte{4, 5, 6} + return inline.AppendInsideInline(val) + }` + eval(t, src, []byte{1, 2, 3, 4, 5, 6}) +} diff --git a/pkg/compiler/testdata/inline/inline.go b/pkg/compiler/testdata/inline/inline.go index 80a7041d9..4f56faa23 100644 --- a/pkg/compiler/testdata/inline/inline.go +++ b/pkg/compiler/testdata/inline/inline.go @@ -64,3 +64,8 @@ func NewT() T { func (t T) GetN() int { return t.N } + +func AppendInsideInline(val []byte) []byte { + inlinedType := []byte{1, 2, 3} + return append(inlinedType, val...) +}