compiler: allow to declare slices of compound types
Previously this declarations were ignored which resulted in runtime errors, because VM's nil is an element of primitive type and can't be converted to an array.
This commit is contained in:
parent
c738975b7b
commit
6baed7a010
3 changed files with 58 additions and 11 deletions
|
@ -3,6 +3,8 @@ package compiler_test
|
|||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||
)
|
||||
|
||||
var sliceTestCases = []testCase{
|
||||
|
@ -128,6 +130,35 @@ var sliceTestCases = []testCase{
|
|||
}`,
|
||||
[]byte{2, 3},
|
||||
},
|
||||
{
|
||||
"declare compound slice",
|
||||
`package foo
|
||||
func Main() []string {
|
||||
var a []string
|
||||
a = append(a, "a")
|
||||
a = append(a, "b")
|
||||
return a
|
||||
}`,
|
||||
[]vm.StackItem{
|
||||
vm.NewByteArrayItem([]byte("a")),
|
||||
vm.NewByteArrayItem([]byte("b")),
|
||||
},
|
||||
},
|
||||
{
|
||||
"declare compound slice alias",
|
||||
`package foo
|
||||
type strs []string
|
||||
func Main() []string {
|
||||
var a strs
|
||||
a = append(a, "a")
|
||||
a = append(a, "b")
|
||||
return a
|
||||
}`,
|
||||
[]vm.StackItem{
|
||||
vm.NewByteArrayItem([]byte("a")),
|
||||
vm.NewByteArrayItem([]byte("b")),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestSliceOperations(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue