compiler: emit Buffer for byte slices

All byte slices are mutable so buffer is a right stack item.
This commit is contained in:
Evgenii Stratonikov 2020-05-13 11:06:12 +03:00
parent b4f1142149
commit 3a4ed7dfe8
3 changed files with 32 additions and 2 deletions

View file

@ -180,6 +180,27 @@ var sliceTestCases = []testCase{
vm.NewByteArrayItem([]byte("b")),
},
},
{
"byte-slice assignment",
`package foo
func Main() []byte {
a := []byte{0, 1, 2}
a[1] = 42
return a
}`,
[]byte{0, 42, 2},
},
{
"byte-slice assignment after string conversion",
`package foo
func Main() []byte {
a := "abc"
b := []byte(a)
b[1] = 42
return []byte(a)
}`,
[]byte{0x61, 0x62, 0x63},
},
}
func TestSliceOperations(t *testing.T) {