compiler: copy locals slice during inline

Consider function call `f(1, g(2, 3))` when
both `f` and `g` are inlined. If `f` contains some locals,
inlining `g` will replace them with it's another locals map,
because slices in Go reuse storage on `append`.
Thus scope needs to be copied.
This commit is contained in:
Evgeniy Stratonikov 2021-02-26 18:02:54 +03:00
parent b66b853285
commit 7577bbef22
3 changed files with 31 additions and 1 deletions

View file

@ -39,7 +39,8 @@ func (c *codegen) inlineCall(f *funcScope, n *ast.CallExpr) {
// while stored in the new.
oldScope := c.scope.vars.locals
c.scope.vars.newScope()
newScope := c.scope.vars.locals
newScope := make([]map[string]varInfo, len(c.scope.vars.locals))
copy(newScope, c.scope.vars.locals)
defer c.scope.vars.dropScope()
hasVarArgs := !n.Ellipsis.IsValid()