build: go fix rewrites a NumField loop into an iterator with a redundant copy that copyloopvar rejects #1653

Closed
opened 2026-10-27 13:41:15 +00:00 by sam · 0 comments
Owner

Found on the cp/config merge (2026-09-21) while running task check on the merged tree.

go fix ./... rewrites this correct, lint-clean Go:

for i := range t.NumField() {
	field := t.Field(i)
	if field.PkgPath != "" { continue }

into this:

for field := range t.Fields() {
	field := field          // <-- redundant under Go 1.22+ loopvar semantics
	if field.PkgPath != "" { continue }

and golangci-lint then fails on the formatter's own output:

internal/infrastructure/configuration/apply.go:216:3: The copy of the 'for' variable "field" can be deleted (Go 1.22+) (copyloopvar)

Measured on go1.27.0 with go.mod's go 1.27.0 (so 1.22 loopvar semantics apply and the copy is never needed):

  • the pre-fix form: golangci-lint 0 issues
  • after go fix: golangci-lint 1 issue (copyloopvar)
  • the iterator form WITHOUT the copy: go fix leaves it alone and golangci-lint reports 0 issues

Because task check runs task fmt (go fix) before task lint, any tree containing the pre-fix shape cannot pass the gate: fmt introduces the copy and lint rejects it. The rewrite is one-shot, not recurring — once the copy is absent, go fix is stable — so removing the copy breaks the cycle, which is what the merge did.

Two things to fix, either of which closes it: keep go fix from inserting the copy for a module whose go directive already implies 1.22+ semantics (upstream go fix behaviour), or stop task fmt applying this particular fix. Worth doing because "task fmt output is LAW" and "never revert a formatter diff" are both standing rules here, and in this case obeying them fails the linter.

Notes

DUPLICATE RISK: the pre-existing branch fix/formatter-single-owner ('fix(build): make formatting and CI converge', 98b80433, 2026-09-20) already changes Taskfile.yml (14 lines) and .golangci.yml (+8) plus .github/workflows/quality.yml for this exact class. Check whether it converges formatting and linting before working this bead; if it does, close this as covered, and if it does not, add this reproduction (go fix introduces the copyloopvar rejection; the copy-free iterator form is stable) to that branch rather than fixing it twice.

Close reason

Fixed in ba37e37e. The fixpoint loop in task fmt (added by 0398ca60) had been silently removed by a later 'reduce Taskfile bloat' refactor (2e00777f), which also deleted the guard test that proved the fixpoint — so the bead was regressed, not merely unaddressed. Restored the loop (go fix passes until go fix -diff ./... exits clean, failing loudly after 10 passes) and restored the guard assertion in TestFormattingUsesOneConfiguredWriter. Mutation-checked: reverting fmt to a single pass fails the guard with 'does not prove that repeated go fix passes have reached a fixpoint'.


Imported from beads archie-core-wwho · GitHub #1141 · type bug · priority P2 · created 2026-09-21 · closed 2026-10-02

Found on the cp/config merge (2026-09-21) while running task check on the merged tree. go fix ./... rewrites this correct, lint-clean Go: for i := range t.NumField() { field := t.Field(i) if field.PkgPath != "" { continue } into this: for field := range t.Fields() { field := field // <-- redundant under Go 1.22+ loopvar semantics if field.PkgPath != "" { continue } and golangci-lint then fails on the formatter's own output: internal/infrastructure/configuration/apply.go:216:3: The copy of the 'for' variable "field" can be deleted (Go 1.22+) (copyloopvar) Measured on go1.27.0 with go.mod's `go 1.27.0` (so 1.22 loopvar semantics apply and the copy is never needed): - the pre-fix form: golangci-lint 0 issues - after `go fix`: golangci-lint 1 issue (copyloopvar) - the iterator form WITHOUT the copy: `go fix` leaves it alone and golangci-lint reports 0 issues Because task check runs task fmt (go fix) before task lint, any tree containing the pre-fix shape cannot pass the gate: fmt introduces the copy and lint rejects it. The rewrite is one-shot, not recurring — once the copy is absent, go fix is stable — so removing the copy breaks the cycle, which is what the merge did. Two things to fix, either of which closes it: keep go fix from inserting the copy for a module whose go directive already implies 1.22+ semantics (upstream go fix behaviour), or stop task fmt applying this particular fix. Worth doing because "task fmt output is LAW" and "never revert a formatter diff" are both standing rules here, and in this case obeying them fails the linter. ### Notes DUPLICATE RISK: the pre-existing branch fix/formatter-single-owner ('fix(build): make formatting and CI converge', 98b80433, 2026-09-20) already changes Taskfile.yml (14 lines) and .golangci.yml (+8) plus .github/workflows/quality.yml for this exact class. Check whether it converges formatting and linting before working this bead; if it does, close this as covered, and if it does not, add this reproduction (go fix introduces the copyloopvar rejection; the copy-free iterator form is stable) to that branch rather than fixing it twice. ### Close reason Fixed in ba37e37e. The fixpoint loop in task fmt (added by 0398ca60) had been silently removed by a later 'reduce Taskfile bloat' refactor (2e00777f), which also deleted the guard test that proved the fixpoint — so the bead was regressed, not merely unaddressed. Restored the loop (go fix passes until go fix -diff ./... exits clean, failing loudly after 10 passes) and restored the guard assertion in TestFormattingUsesOneConfiguredWriter. Mutation-checked: reverting fmt to a single pass fails the guard with 'does not prove that repeated go fix passes have reached a fixpoint'. --- _Imported from beads `archie-core-wwho` · GitHub #1141 · type bug · priority P2 · created 2026-09-21 · closed 2026-10-02_
sam added the mediumbug labels 2026-10-27 13:41:15 +00:00
sam self-assigned this 2026-10-27 13:41:15 +00:00
sam closed this issue 2026-10-27 13:41:15 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1653