You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Go: a local that is declared but never read fails to compile ("declared and not used") #272
Go refuses any local variable that nothing reads. GoGenerator.GenerateVariableDeclaration (Coder/Languages/GoGenerator.cs ~L1327 onward) writes var t int = 3 or t := … and nothing else.
A body that declares a local and never reads it, or only assigns to it, is valid in the other six targets. Its Go output doesn't compile:
funcunused() int {
vartint=3// declared and not used: treturn1
}
The generator already handles this rule in one place. GenerateEntryPoint (~L1937-L1980) writes _ = args, "since Go refuses a local nothing reads and a body is free to ignore its arguments". The same applies to every local that comes from a VariableDeclaration.
Generate as Go, wrap the output in package main, and run go build. It fails with declared and not used: t.
Suggested fix
Follow a local's declaration with _ = <name>. There are two ways to do it:
Simplest: add the line after every local.
Tidier: add it only when nothing later in the enclosing body reads the name. The StaticTypeScope walk in StandardLanguageGenerator (~L249-L258) already visits a body's locals and could host that check.
Either way, the output has to stay gofmt-clean.
Acceptance criteria
The function above compiles under GoGeneratedSourceCompilesTests, which still checks the output against gofmt.
If the tidier version is chosen, a local that is read later gets no _ = line.
Priority: Medium. Any body with a local that is never read produces Go that doesn't compile. The failure is loud, but unused or write-only locals are common in real input, so it will be hit often.
Area / suggested assignee:GoGenerator.GenerateVariableDeclaration; the existing _ = args in GenerateEntryPoint is the precedent. Owner: @matt-edmondson
Next step: start with the simple version (_ = name after every local) to get GoGeneratedSourceCompilesTests green; move to the read-analysis version only if the extra lines are judged too noisy.
Activity
matt-edmondson commentedon Oct 19, 2026
Triage
GoGenerator.GenerateVariableDeclaration; the existing_ = argsinGenerateEntryPointis the precedent. Owner: @matt-edmondson_ = nameafter every local) to getGoGeneratedSourceCompilesTestsgreen; move to the read-analysis version only if the extra lines are judged too noisy.Generated by Claude Code