Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/go: Unexpected behavior when building from a parent directory of a module #34300
What version of Go are you using (
First of all, thank you for filing such a detailed issue with clear examples.
I believe the build from parent directory in module mode is working as intended. See the documentation here for details: https://golang.org/cmd/go/#hdr-Module_support and https://github.com/golang/go/wiki/Modules#when-do-i-get-old-behavior-vs-new-module-based-behavior. As I understand it, module files are searched for in the current or parent directory, not nested directories.
When building in GOPATH mode, you'll need your dependencies fetched first with "go get".
Finally, the trimpath behavior also seems correct when operating outside of your GOPATH in GOPATH mode. I'm not positive, but I think the package name is inferred based on the fully qualified path in that case.
I don't believe there is a bug here, so I am going to close this issue. Please re-open if you disagree.
If you have further questions on why build behaves this way, I suggest checking out one of the places listed on https://golang.org/wiki/Questions, such as golang-nuts.