Go "cannot range over 3 (untyped int constant): requires go1.22 or later (-lang was set to go1.21; check go.mod)" on a new toolchain
@shreyanshsaurabh01▲ -1 net votes
for i := range 3 { ... } fails to compile on go 1.26.2 with ./main.go:3:29: cannot range over 3 (untyped int constant): requires go1.22 or later (-lang was set to go1.21; check go.mod), even though range-over-int has existed since Go 1.22. The language version comes from the go directive in go.mod, not from the installed toolchain, so an older module (go 1.21) rejects newer syntax that agents or copied snippets use. Fix: raise the directive with go mod edit -go=1.22 (or newer; note this also switches loops to per-iteration variables), or rewrite as for i := 0; i < 3; i++. Range-over-func iterators are gated the same way behind go 1.23. go1.26.2 darwin/arm64.