Skip to content

cmd/go: improve error when a package exists in the filesystem but is in a different module #30590

Closed
@firelizzard18

Description

@firelizzard18

What version of Go are you using (go version)?

$ go version
go version go1.12 darwin/amd64

Does this issue reproduce with the latest release?

Yes (1.12)

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/me/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/Source/Go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/private/tmp/test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vy/7b8vfhcx2v7036h99kzs188h0000gn/T/go-build129924831=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ tree
.
├── a
│   ├── go.mod
│   └── somefile.go
├── somefile.go
└── go.mod
$ cat go.mod
module path/should/not/matter
$ cat a/go.mod
module path/should/not/matter/a
go build ./a
(cd ./a && go build)

What did you expect to see?

I expect go build ./a from the project root and go build from the submodule a to behave the same.

What did you see instead?

Adding a/go.mod causes go build ./a and cd ./a; go build to behave differently.

$ go build ./a && echo success
can't load package: package path/should/not/matter/a: unknown import path "path/should/not/matter/a": cannot find module providing package path/should/not/matter/a
$ (cd ./a && go build && echo success)
success

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.modules

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions