fix(gengo): scope _v in array compound-assign to avoid Go redeclaration
emitAssign for arr[i] op= rhs emitted bare _v := t.Pop2(), so functions with multiple compound assigns to array elements failed to build with "no new variables on left side of :=". Wrap the snippet in a block so each occurrence has its own _v scope (same pattern as gengo.go:1335). Repro: any PRG with two or more arr[i] += x or arr[i][j] += x in the same function (e.g. labdb session-stats.prg with 6-channel peak accumulators). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -461,11 +461,12 @@ func (g *Generator) emitAssign(a *ast.AssignExpr, locals localMap) {
|
||||
g.emitExpr(a.Right)
|
||||
g.emitBinaryOp(a.Op)
|
||||
// Stack now: [folded value]. Re-push X/index to set.
|
||||
g.writeln("_v := t.Pop2()")
|
||||
// Scope _v so multiple compound assigns in the same function don't redeclare.
|
||||
g.writeln("{ _v := t.Pop2()")
|
||||
g.emitExpr(idx.X)
|
||||
g.emitExpr(idx.Index)
|
||||
g.writeln("t.PushValue(_v)")
|
||||
g.writeln("t.ArrayPop()")
|
||||
g.writeln("t.ArrayPop() }")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user