diff --git a/pkg/compiler/codegen.go b/pkg/compiler/codegen.go index 3872be99b..9dadbeff9 100644 --- a/pkg/compiler/codegen.go +++ b/pkg/compiler/codegen.go @@ -235,7 +235,8 @@ func (c *codegen) emitDefault(t types.Type) { if isCompoundSlice(t) { emit.Opcode(c.prog.BinWriter, opcode.NEWARRAY0) } else { - emit.Bytes(c.prog.BinWriter, []byte{}) + emit.Int(c.prog.BinWriter, 0) + emit.Opcode(c.prog.BinWriter, opcode.NEWBUFFER) } case *types.Struct: emit.Int(c.prog.BinWriter, int64(t.NumFields())) diff --git a/pkg/compiler/slice_test.go b/pkg/compiler/slice_test.go index d6829925b..af7d07f80 100644 --- a/pkg/compiler/slice_test.go +++ b/pkg/compiler/slice_test.go @@ -201,6 +201,17 @@ var sliceTestCases = []testCase{ }`, []byte{0x61, 0x62, 0x63}, }, + { + "declare and append byte-slice", + `package foo + func Main() []byte { + var a []byte + a = append(a, 1) + a = append(a, 2) + return a + }`, + []byte{1, 2}, + }, } func TestSliceOperations(t *testing.T) {