Fix append for bytearrays (#64)

This commit is contained in:
Anthony De Meulemeester 2018-04-05 10:35:33 +02:00 committed by GitHub
parent 941bd7e728
commit 5b5a7106c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -1 +1 @@
0.39.0
0.39.1

View file

@ -225,6 +225,21 @@ func TestIfUnaryInvert(t *testing.T) {
eval(t, src, big.NewInt(0))
}
func TestAppendByte(t *testing.T) {
src := `
package foo
func Main() []byte {
arr := []byte{0x00, 0x01, 0x02}
arr = append(arr, 0x03)
arr = append(arr, 0x04)
arr = append(arr, 0x05)
arr = append(arr, 0x06)
return arr
}
`
eval(t, src, []uint8{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06})
}
func TestAppendString(t *testing.T) {
src := `
package foo

View file

@ -483,6 +483,9 @@ func (v *VM) execute(ctx *Context, op Opcode) {
arr := t.Value().([]StackItem)
arr = append(arr, itemElem.value)
v.estack.PushVal(arr)
case *ByteArrayItem:
newVal := append(t.value, itemElem.value.Value().([]byte)...)
v.estack.PushVal(newVal)
default:
panic("APPEND: not of underlying type Array")
}