mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
compiler: process empty []byte{} literals as ByteArrays
It is wrong to count an empty byte slice as an Array.
This commit is contained in:
parent
32bce30777
commit
8ea3ef0b62
2 changed files with 18 additions and 0 deletions
|
@ -189,6 +189,12 @@ func isBuiltin(expr ast.Expr) bool {
|
|||
|
||||
func isByteArray(lit *ast.CompositeLit, tInfo *types.Info) bool {
|
||||
if len(lit.Elts) == 0 {
|
||||
if typ, ok := lit.Type.(*ast.ArrayType); ok {
|
||||
if name, ok := typ.Elt.(*ast.Ident); ok {
|
||||
return name.Name == "byte" || name.Name == "uint8"
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -293,6 +293,18 @@ func TestAppendByte(t *testing.T) {
|
|||
eval(t, src, []uint8{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06})
|
||||
}
|
||||
|
||||
func TestAppendByteToEmpty(t *testing.T) {
|
||||
src := `
|
||||
package foo
|
||||
func Main() []byte {
|
||||
out := []byte{}
|
||||
out = append(out, 1)
|
||||
out = append(out, 2)
|
||||
return out
|
||||
}`
|
||||
eval(t, src, []byte{1, 2})
|
||||
}
|
||||
|
||||
func TestAppendString(t *testing.T) {
|
||||
src := `
|
||||
package foo
|
||||
|
|
Loading…
Reference in a new issue