Repository: go
Issue: cmd/go: in module root, go list {module-root}/... behaves differently than go list ./..., yet go mod tidy removes go.sum entry needed for former
Labels: Documentation,Thinking,NeedsInvestigation,GoCommand,modules

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.18rc1 darwin/arm64
</pre>

### Does this issue reproduce with the latest release?

It reproduces with `go1.18rc1`.

Not really viable to test with Go 1.17.7 because it happens in a module whose go.mod file has `go 1.18`, so `go1.17.7 mod tidy` refuses to run on it:

```
$ go1.17.7 mod tidy
go mod tidy: go.mod file indicates go 1.18, but maximum supported version is 1.17
```

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/dmitri/Library/Caches/go-build"
GOENV="/Users/dmitri/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/dmitri/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/dmitri/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18rc1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_0/h0671fcn4rgb5pn9c745dx2h0000gn/T/go-build1161277448=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

I ran `go mod tidy` inside a module that declares `go 1.18`. It removed one line from go.sum. Then I tried running `go list {module-root}/...` and `go list ./...` while being at the module root directory, without using the new workspace mode (that is, `go env GOWORK` output was blank).

(See the bottom of this issue for a sequence of exact commands that reproduce the issue.)

### What did you expect to see?

I expected both `go list {module-root}/...` and `go list ./...` to work, and produce identical output, given the current working directory is the module root.

(I also expected that the amount of work needed to process these two relative and full import path patterns would be approximately the same. If that's not the case, I'm interested in learning what makes them different.)

### What did you see instead?

Running `go mod tidy` causes the following line to be removed from go.sum:

```
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU=
```

Then, when I ran `go list {module-root}/...`, it failed:

```
$ go list golang.org/x/exp/shiny/...
pattern golang.org/x/exp/shiny/...: golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56: missing go.sum entry
```

Notably, it's saying the go.sum entry from `golang.org/x/exp@v0.0.0-20190731235908-ec7cb31e5a56` is missing, the very same one that `go mod tidy` removed earlier.

`go list ./...` works well.

```
$ go list ./...
golang.org/x/exp/shiny/driver
golang.org/x/exp/shiny/driver/gldriver
[...]
golang.org/x/exp/shiny/widget/node
golang.org/x/exp/shiny/widget/theme
$ go list ./... | shasum
19cedcfaf7f294abf33a6ef54a81560517aa8a8d  -
```

If I manually add the missing go.sum entry back, then the longer go list invocation produces an identical result:

```
$ go list golang.org/x/exp/shiny/... | shasum
19cedcfaf7f294abf33a6ef54a81560517aa8a8d  -
```

### Sequence of commands to reproduce

```
export GOPATH=$(mktemp -d)
cd $(mktemp -d)
git clone https://go.googlesource.com/exp && cd exp
git checkout 6cf2b201936e0673ace5b31d2dffa00dafb3ee58
cd shiny
go mod tidy
go list ./...
go list golang.org/x/exp/shiny/...
echo $?
```

CC @bcmills, @matloob.