compiler: support ... variadic calls

This commit is contained in:
Evgenii Stratonikov 2020-06-27 10:39:30 +03:00
parent b9171eda14
commit 057e1e2806
2 changed files with 18 additions and 5 deletions

View file

@ -758,8 +758,9 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
}
// Do not swap for builtin functions.
if !isBuiltin {
if typ, ok := c.typeOf(n.Fun).(*types.Signature); ok && typ.Variadic() {
// pack variadic args into an array
typ, ok := c.typeOf(n.Fun).(*types.Signature)
if ok && typ.Variadic() && !n.Ellipsis.IsValid() {
// pack variadic args into an array only if last argument is not of form `...`
varSize := len(n.Args) - typ.Params().Len() + 1
c.emitReverse(varSize)
emit.Int(c.prog.BinWriter, int64(varSize))