Skip to content

Comments

all: test: remove unneeded loop variables#77694

Open
ariel-anieli wants to merge 1 commit intogolang:masterfrom
ariel-anieli:modernize-forvar-issue-76411
Open

all: test: remove unneeded loop variables#77694
ariel-anieli wants to merge 1 commit intogolang:masterfrom
ariel-anieli:modernize-forvar-issue-76411

Conversation

@ariel-anieli
Copy link
Contributor

@ariel-anieli ariel-anieli commented Feb 18, 2026

This CL follows from the abandoned CL 722961.

Alan Donovan asked if modernize would catch these changes; it does in part.

Here is how modernize was used:

  1. Build the Go compiler from latest master

  2. Clone x/tools and build modernize with the newest compiler

  3. Then, do:

    PATH=PATH_TO_BIN:$PATH go list ./... | xargs env PATH=PATH_TO_BIN:$PATH GOMOD=off MODERNIZE -forvar -fix -test -debug fpstv

  4. For assurance, move into a package directory (i.e, cmd), and redo Step 3.

From the obtained result, it seems modernize did not remove the loop variable when:

  • the range notation was not used
  • the loop variable was not directly under the for directive.

Which does happens here:

# git ls-files | xargs -I {} perl -nE 'print "$ARGV:$.:$_" if /\s+(\w+) := \1$/' {} | grep _test
[...]
cmd/compile/internal/types2/api_test.go:2423:                   i := i
md/go/internal/modload/query_test.go:182:              tt := tt
md/go/internal/web/url_test.go:17:             tc := tc
cmd/go/internal/web/url_test.go:49:             tc := tc
cmd/internal/par/queue_test.go:54:              i := i
runtime/syscall_windows_test.go:781:            arglen := arglen

Link: https://go-review.googlesource.com/c/go/+/722961/comments/e8d47866_fc399fa1
Co-authored-by: Plamerdi Makela plamerdi447@gmail.com
Fixes #76411

@gopherbot
Copy link
Contributor

This PR (HEAD: f7c955d) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/746502.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ariel Otilibili Anieli:

Patch Set 1:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alan Donovan:

Patch Set 2: Code-Review+2

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Jorropo:

Patch Set 2: Code-Review+2

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

This CL follows from the abandoned CL 722961.

Alan Donovan asked if modernize would catch these changes; it does in part.

Here is how modernize was used:
1. Build the Go compiler from latest master
2. Clone x/tools and build modernize with the newest compiler
3. Then, do:

    PATH=PATH_TO_BIN:$PATH go list ./... | xargs env PATH=PATH_TO_BIN:$PATH GOMOD=off MODERNIZE -forvar -fix -test -debug fpstv

4. For assurance, move into a package directory (i.e, cmd), and redo Step 3.

From the obtained result, it seems modernize did not remove the loop variable when:
- the range notation was not used
- the loop variable was not directly under the for directive.

Which does happens here:

    # git ls-files | xargs -I {} perl -nE 'print "$ARGV:$.:$_" if /\s+(\w+) := \1$/' {} | grep _test
    [...]
    cmd/compile/internal/types2/api_test.go:2423:                   i := i
    md/go/internal/modload/query_test.go:182:              tt := tt
    md/go/internal/web/url_test.go:17:             tc := tc
    cmd/go/internal/web/url_test.go:49:             tc := tc
    cmd/internal/par/queue_test.go:54:              i := i
    runtime/syscall_windows_test.go:781:            arglen := arglen

Fixes golang#76411.
Link: https://go-review.googlesource.com/c/go/+/722961/comments/e8d47866_fc399fa1
Co-authored-by: Plamerdi Makela <plamerdi447@gmail.com>
@ariel-anieli ariel-anieli force-pushed the modernize-forvar-issue-76411 branch from f7c955d to 77c3e11 Compare February 24, 2026 01:18
@gopherbot
Copy link
Contributor

This PR (HEAD: 77c3e11) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/746502.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link
Contributor

Message from Ariel Otilibili Anieli:

Patch Set 2:

(4 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alan Donovan:

Patch Set 3: Auto-Submit+1 Code-Review+2 Commit-Queue+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 3:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-02-24T01:27:29Z","revision":"7d4f8be5469fd932cde049312a9f2a967e4eb894"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alan Donovan:

Patch Set 3: -Commit-Queue

(Performed by golang-scoped@luci-project-accounts.iam.gserviceaccount.com on behalf of adonovan@google.com)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 3:

This CL has failed the run. Reason:

Failed Tryjobs:


To reproduce, try gomote repro 8689025619902132097.

Additional links for debugging:



To reproduce, try gomote repro 8689025619902132081.

Additional links for debugging:



Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 3: LUCI-TryBot-Result-1


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ariel Otilibili Anieli:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alan Donovan:

Patch Set 4: Auto-Submit+1 Code-Review+2 Commit-Queue+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 4:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-02-24T01:47:51Z","revision":"0836553c6a25aeafeafbc56603e2935a3a1bd648"}


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ariel Otilibili Anieli:

Patch Set 4:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alan Donovan:

Patch Set 4: -Commit-Queue

(Performed by golang-scoped@luci-project-accounts.iam.gserviceaccount.com on behalf of adonovan@google.com)


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 4:

This CL has failed the run. Reason:

Tryjob golang/try/gotip-linux-amd64-boringcrypto has failed with summary (view all results):


To reproduce, try gomote repro 8689024338119324929.

Additional links for debugging:


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go LUCI:

Patch Set 4: LUCI-TryBot-Result-1


Please don’t reply on this GitHub thread. Visit golang.org/cl/746502.
After addressing review feedback, remember to publish your drafts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

all: remove unneeded loop variables in tests

2 participants