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.
This commit is contained in:
Anna Shaleva 2022-09-27 14:35:13 +03:00
parent 3dbd36ef70
commit 5d578fdd95
3 changed files with 17 additions and 1 deletions

View file

@ -1819,7 +1819,7 @@ func (c *codegen) convertBuiltin(expr *ast.CallExpr) {
emit.Opcodes(c.prog.BinWriter, opcode.DROP, opcode.PUSH0) emit.Opcodes(c.prog.BinWriter, opcode.DROP, opcode.PUSH0)
case "append": case "append":
arg := expr.Args[0] arg := expr.Args[0]
typ := c.typeInfo.Types[arg].Type typ := c.typeOf(arg)
ast.Walk(c, arg) ast.Walk(c, arg)
emit.Opcodes(c.prog.BinWriter, opcode.DUP, opcode.ISNULL) emit.Opcodes(c.prog.BinWriter, opcode.DUP, opcode.ISNULL)
if isByteSlice(typ) { if isByteSlice(typ) {

View file

@ -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})
}

View file

@ -64,3 +64,8 @@ func NewT() T {
func (t T) GetN() int { func (t T) GetN() int {
return t.N return t.N
} }
func AppendInsideInline(val []byte) []byte {
inlinedType := []byte{1, 2, 3}
return append(inlinedType, val...)
}