From d9123acdcea9243938349ea0e1ba28f35b7c3024 Mon Sep 17 00:00:00 2001 From: Charles KWON OhJun Date: Wed, 27 May 2026 09:14:49 +0900 Subject: [PATCH] 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) --- compiler/gengo/emit_stmt.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/gengo/emit_stmt.go b/compiler/gengo/emit_stmt.go index 009d829..8252805 100644 --- a/compiler/gengo/emit_stmt.go +++ b/compiler/gengo/emit_stmt.go @@ -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 }