interp: do not skip use of tmp frame in multi-assign

Fixes #1052.
This commit is contained in:
Marc Vertes
2021-03-19 11:24:04 +01:00
committed by GitHub
parent 7d8fdbc1fc
commit ec5392d566
2 changed files with 24 additions and 1 deletions

23
_test/issue-1052.go Normal file
View File

@@ -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

View File

@@ -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]