4 ms·
They broke the foreach loop behavior in 1.22, mainly to make it match what people expected. https://go.dev/blog/loopvar-preview https://go.dev/blog/loopvar-pre
by kyrra 1y ago
They broke the foreach loop behavior in 1.22, mainly to make it match what people expected.
https://go.dev/blog/loopvar-preview https://go.dev/blog/loopvar-preview
- tgv 1y agoSmall, but significant point: you can easily avoid the new behavior. IIRC, if you had a pre-1.22 project, and didn't change anything, it still compiles as before. So if you relied on that behavior (which would be very weird, but who knows), backwards compatibility is still there for you.
- kyrra 1y agoIt defaults to the new behavior. If you want the old behavior, you had to set a flag on the compiler. But this applies to all code, so any libraries you include would also get whatever behavior you set on the flag.