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:
parent
b66b853285
commit
7577bbef22
3 changed files with 31 additions and 1 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue