Skip to content

ssa: modernize go for variables (forvar)#1073

Closed
matheuscscp wants to merge 1 commit intomainfrom
modernize-go
Closed

ssa: modernize go for variables (forvar)#1073
matheuscscp wants to merge 1 commit intomainfrom
modernize-go

Conversation

@matheuscscp
Copy link
Copy Markdown
Member

Today I saw this message in my IDE:

Screenshot from 2026-01-16 06-01-10

Then I found this:

https://go.dev/doc/go1.22#language

Starting with Go 1.22, for variables are recreated on every iteration, instead of being created only once in the beginning and then updated.

I have used this variable copy+shadowing many times before inside loops and understand why this was needed before Go 1.22, so I'm glad to learn about this improvement.

This language improvement also eliminates the need for this pattern (which also exists in a few places in our codebase):

for i, x := range someSlice {
  go func(i int, x someType) { // these args are no longer needed
    // do something with i and x
  }(i, x)
}

Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
@matheuscscp
Copy link
Copy Markdown
Member Author

@matheuscscp matheuscscp deleted the modernize-go branch January 19, 2026 19:31
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.

1 participant