Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
For-Loop Semantic Changes in Go 1.22: Be Aware of the Impact (go101.org)
10 points by tapirl on March 2, 2024 | hide | past | favorite | 6 comments


It's about time they finally acknowledge this as a design bug and make the incompatible fix. In pre-1.22 correct programs, the `i, v := i, v` will mostly already be present and become pointless upon upgrading. Libraries supporting pre-1.22 will still have to write this extra line.

Now we have a new foot-gun, moving working code from a 1.22+ program to a pre-1.22 supporting library can be bugged.


Would it be accurate to say that the variable values are fresh per iteration as of 1.22 and fresh only per initialization prior? I was looking for a falsification of that description in the text.


Could you elaborate more on "fresh only per initialization prior"? I don't very get it.


Fresh only per initialization in go 1.21 and earlier.

Fresh refers to when the variable is apparently initialized with a value.


> Would it be accurate to say that the variable values are fresh per iteration as of 1.22 and fresh only per initialization prior?

Yes, if the loop variables are declared in the init-statement of a loop (using := ).


This looks like the kind of subtle change that will lead to unexpected security issues.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: