compiler: emit error for non-byte subslices

They are not supported for now, as VM has only
`SUBSTR` opcode for Buffers (`[]byte` in Go).
This commit is contained in:
Evgenii Stratonikov 2020-09-15 09:52:56 +03:00
parent 3f27cf5901
commit 78948ef7af
2 changed files with 15 additions and 0 deletions

View file

@ -517,6 +517,10 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
return nil
case *ast.SliceExpr:
if isCompoundSlice(c.typeOf(n.X.(*ast.Ident)).Underlying()) {
c.prog.Err = errors.New("subslices are supported only for []byte")
return nil
}
name := n.X.(*ast.Ident).Name
c.emitLoadVar("", name)