Description
What version of Go are you using (go version
)?
$ go version go version go1.11.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/Users/deklerk/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/deklerk/workspace/go" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" 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/lk/zs4m7sv12mq2vzk_wfn2tfvm00h16k/T/go-build259032920=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
- Create repo
foo
with:- A
foo/go.mod
- A
foo/somefile.go
containingconst Version = "foo=0.0.1"
- A directory
foo/bar/
with afoo/bar/somefile.go
containingconst Version = "foo=0.0.1"
- A
- Commit, tag v0.0.1 (parent encompasses directory), push both
...
- In some other library, depend on foo with
require foo v0.0.1
- Add
fmt.Println(foo.Version) // expect "foo=0.0.1"
- Add
fmt.Println(bar.Version) // expect "foo=0.0.1"
...
- Back in repo
foo
, make afoo/bar
its own submodule:- Create
foo/bar/go.mod
- Update
foo/bar/somefile.go
to now haveconst Version = "bar=1.0.0"
- Commit, tag bar/v1.0.0, tag v0.0.2 (new version of the parent because a submodule was carved out), and push all
- Create
...
- In your other library, add a
require bar v1.0.0
dependency (keeping therequire foo v0.0.1
dependency!) - Now you require "bar" two ways: via
require bar v1.0.0
and viarequire foo v0.0.1
, in whichfoo/bar
was still part of the module fmt.Println(bar.Version)
results inbar=1.0.0
EDIT: actually, you get the following error (see @myitcv excellent repro below):
```
unknown import path "github.com/jadekler/module-testing/pkg_b": ambiguous import: found github.com/jadekler/module-testing/pkg_b in multiple modules:
```
What did you expect to see?
I'm not sure. Maybe this is WAI? I vaguely expected to see an error. I suspect there are some hidden subtleties here that could end up breaking people. Maybe since bar has to always be backwards compatible, this is OK?
Anyways, feel free to close if this is unsurprising. I thought it was subtle and maybe worth looking at, but y'all let me know.
EDIT: Ignore this, since my original post was flawed. In fact you cannot do this, which seems to imply carving out submodules after-the-fact is unsupported.
What did you see instead?
Go modules seems to silently replace foo/bar/
in the require foo v0.0.1
with the bar v1.0.0
version.
EDIT: Ignore this, since my original post was flawed. In fact you cannot do this, which seems to imply carving out submodules after-the-fact is unsupported.