diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index ad46b8b93..bf3272baa 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -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 } diff --git a/pkg/compiler/for_test.go b/pkg/compiler/for_test.go index 83b460517..6c3f67b87 100644 --- a/pkg/compiler/for_test.go +++ b/pkg/compiler/for_test.go @@ -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