parent
3a4ed7dfe8
commit
1a4a0c154b
2 changed files with 13 additions and 1 deletions
|
@ -235,7 +235,8 @@ func (c *codegen) emitDefault(t types.Type) {
|
||||||
if isCompoundSlice(t) {
|
if isCompoundSlice(t) {
|
||||||
emit.Opcode(c.prog.BinWriter, opcode.NEWARRAY0)
|
emit.Opcode(c.prog.BinWriter, opcode.NEWARRAY0)
|
||||||
} else {
|
} else {
|
||||||
emit.Bytes(c.prog.BinWriter, []byte{})
|
emit.Int(c.prog.BinWriter, 0)
|
||||||
|
emit.Opcode(c.prog.BinWriter, opcode.NEWBUFFER)
|
||||||
}
|
}
|
||||||
case *types.Struct:
|
case *types.Struct:
|
||||||
emit.Int(c.prog.BinWriter, int64(t.NumFields()))
|
emit.Int(c.prog.BinWriter, int64(t.NumFields()))
|
||||||
|
|
|
@ -201,6 +201,17 @@ var sliceTestCases = []testCase{
|
||||||
}`,
|
}`,
|
||||||
[]byte{0x61, 0x62, 0x63},
|
[]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) {
|
func TestSliceOperations(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue