Re:Fixing for Loops in Go 1.22
by matthewmueller on Tuesday September 19, 2023 @04:01PM
(#37575656)
It's only enabled for modules that run Go 1.22 and higher
[ Parent
| on HN ]
Re:Fixing for Loops in Go 1.22
by badrequest on Tuesday September 19, 2023 @04:04PM
(#37575725)
I also can't imagine a case where it is useful or even truly intended to rely on this behavior.
Re:Fixing for Loops in Go 1.22
by omginternets on Tuesday September 19, 2023 @04:17PM
(#37575904)
Yeah it’s def a code smell …
Yeah I don't think it's so much "we explicitly rely on this behavior, how dare you change this" as "somewhere in our mountains of maintenance-mode code that haven't seen the sun shine through an editor window in years, this behavior cancels out another bug that we never noticed". Tooling should be able to detect when code relies on this, but it's still gonna cost some non-zero amount of developer effort to touch ancient code and safely roll out a new version if it needs to be actively addressed.
If you have tests and they break with GOEXPERIMENT=loopvar, then there is a new tool that will tell you exactly which loop is causing the breakage. That's a post for a few weeks from now.
Re:Fixing for Loops in Go 1.22
by kuchenbecker on Tuesday September 19, 2023 @09:34PM
(#37579419)
If
Neither can I, but there may be cases of code accidentally relying on it - there's an adage that I forgot the name of that says just that, and I think compiler manufacturers are the most aware of that adage.