Skip to content

Commit

Permalink
interp: do not skip use of tmp frame in multi-assign
Browse files Browse the repository at this point in the history
Fixes #1052.
  • Loading branch information
mvertes committed Mar 17, 2021
1 parent 7d8fdbc commit 3dfaae5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions _test/issue-1052.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import "fmt"

func main() {
a, b := 1, 1
for i := 0; i < 10; i++ {
fmt.Println(a)
a, b = b, a+b
}
}

// Output:
// 1
// 1
// 2
// 3
// 5
// 8
// 13
// 21
// 34
// 55
2 changes: 1 addition & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ func (interp *Interpreter) cfg(root *node, importPath string) ([]*node, error) {
// by constOp and available in n.rval. Nothing else to do at execution.
n.gen = nop
n.findex = notInFrame
case n.anc.kind == assignStmt && n.anc.action == aAssign:
case n.anc.kind == assignStmt && n.anc.action == aAssign && n.anc.nleft == 1:
// To avoid a copy in frame, if the result is to be assigned, store it directly
// at the frame location of destination.
dest := n.anc.child[childPos(n)-n.anc.nright]
Expand Down

0 comments on commit 3dfaae5

Please sign in to comment.