Closed
Description
(I haven't dug into exactly what dependency is causing this or why, but I've managed to whittle the issue down to a fairly manageable no-code repro case.)
What version of Go are you using (go version
)?
$ go version go 1.12.1
Does this issue reproduce with the latest release?
Yes. I haven't checked against tip.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/rlight2/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/rlight2" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/rlight2/src/mg-repro/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build158725968=/tmp/go-build -gno-record-gcc-switches"
What did you do?
git clone https://gist.github.com/5513fc51a179cfd757dcdd1d7c1e4995.git mod-tidy-issue
cd mod-tidy-issue
go mod tidy
go build -mod=readonly
What did you expect to see?
A successful build of the binary.
What did you see instead?
go: updates to go.mod needed, disabled by -mod=readonly
Additional surrounding steps
Running go build
will cause go build -mod=readonly
to pass. Doing this adds lines (all marked "indirect") for:
github.com/golang/mock
gopkg.in/check.v1
gopkg.in/yaml.v2
However, running go mod tidy
on this go.mod will unceremoniously remove these added lines. Most confusingly, go mod why
doesn't seem to know why these lines are there either:
$ go mod why -m gopkg.in/yaml.v2
# gopkg.in/yaml.v2
(main module does not need module gopkg.in/yaml.v2)