-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
compiler detects module based on current working directory #68043
Comments
Adding to the confusion, the 1.22 compiler will compile with 1.22 loop semantics when it cannot find the go.mod file, even though it will also use the 1.21 |
I believe this is working as intended for your setting of
Using the module based on the |
@seankhliao then the behavior ought to be revisited, as it is completely undesirable and unexpected. The toolchain should go by the go.mod file for the code being built; the current working directory should never be relevant. |
Go version
go version go1.22.4 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
We originally noticed this issue because
debug.ReadBuildInfo()
was not reporting the expected value forDefaultGODEBUG
.It seems that
go build
will only detect that we are building a module if the current working directory is with the module root.What did you see happen?
It ignores go.mod completely, and uses the 1.21
DefaultGODEBUG
settings.Inside the module folder:
go build && ./godebugbug
Outside the module folder:
go build -o main ./godebugbug && ./main
What did you expect to see?
It should instead detect it based upon the target package being within a module.
That is, if I run
go build ./foo/bar/baz
, where the go.mod file is located at ./foo/go.mod, then it should detect the module and build properly, using theDefaultGODEBUG
that goes with the version of Go listed in the go.mod file.The text was updated successfully, but these errors were encountered: