Repository: go
Issue: cmd/go: add (or make explicit) tests for ambiguous imports in module mode
Labels: Testing,NeedsFix,GoCommand,modules

<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.11.2 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes.


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ 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"
</pre></details>

### What did you do?

- Create repo `foo` with:
  - A `foo/go.mod`
  - A `foo/somefile.go` containing `const Version = "foo=0.0.1"`
  - A directory `foo/bar/` with a `foo/bar/somefile.go` containing `const Version = "foo=0.0.1"`
- 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 a `foo/bar` its own submodule:
  - Create `foo/bar/go.mod`
  - Update `foo/bar/somefile.go` to now have `const 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

...

- In your other library, add a `require bar v1.0.0` dependency (keeping the `require foo v0.0.1` dependency!)
- Now you require "bar" two ways: via `require bar v1.0.0` and via `require foo v0.0.1`, in which `foo/bar` was still part of the module
- `fmt.Println(bar.Version)` results in `bar=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.