-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import/path: Loops no longer share loop variablesRunning them in different ways gives different results #69704
Comments
I seem to have found the problem, the reason is that my go.mod file does not indicate the version number, but then there is a question, I only have the current version of the go compiler locally, and there is no multi-version management tool, since the support indicates the version of go, but it should also use my current go compiler, right? Is this a flaw? |
It goes back to the old behaviour for backwards compatibility if the Go version in go.mod is <= 1.22. https://go.dev/blog/loopvar-preview "To ensure backwards compatibility with existing code, the new semantics will only apply in packages contained in modules that declare go 1.22 or later in their go.mod files." |
I'm referring to the fact that my mod file doesn't specify a go version, but I only have a local compiler version of 1.23.0. |
If it doesn't specify a Go version then the go tool acts as if you had written "go 1.11" in it, since module support was introduced in Go 1.11.. |
If I don't specify a version in the go mod, even though the compiler I have installed is 1.23.0 Since I didn't specify it, he will automatically downgrade and use go 1.11 by default? |
It will act as if go.mod said "go 1.11", that's not the same as downgrading to Go 1.11 for everything. Some features are gated by the go line in go.mod, and it won't enable these changes. For example, you won't be able to use generics, either. |
thanks bro。 |
Go version
go version go1.23.0 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Code:
What did you see happen?
Running via
go run .
result:
Running via
go run main.go
result:
What did you expect to see?
The expected result should be the way to run it through the file, but why the other ways to run it get different results is very puzzling to me
The text was updated successfully, but these errors were encountered: