Skip to content

cmd/doc: 'go doc $pkg' prefers GOPATH instead of active module #28992

Closed
@bcmills

Description

@bcmills

go doc calls out to cmd/doc, and cmd/doc implicitly uses GOPATH to resolve the imports instead of looking in the active modules. That results in unexpected skew: it produces spurious failures when the package exists but is not in GOPATH, and spurious documentation if GOPATH contains unpublished changes (as in the example in the details below).

This is one instance of #24661, but the tool in question happens to be bundled with cmd/go and released with the Go toolchain: we should fix it sooner rather than later.

CC @robpike @mvdan @ianthehat @rsc

~/src/golang.org/x/build$ export GO111MODULE=on

~/src/golang.org/x/build$ go version
go version devel +d8b7a9286d Wed Nov 28 13:07:32 2018 -0500 linux/amd64

~/src/golang.org/x/build$ go list -m golang.org/x/tools
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b

~/src/golang.org/x/build$ go list golang.org/x/tools/cmd/goforward
go: downloading golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b
go: extracting golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b
go: finding golang.org/x/tools/cmd/goforward latest
go: finding golang.org/x/tools/cmd latest
go: finding golang.org/x/tools latest
go: downloading golang.org/x/tools v0.0.0-20181127232545-e782529d0ddd
go: extracting golang.org/x/tools v0.0.0-20181127232545-e782529d0ddd
can't load package: package golang.org/x/tools/cmd/goforward: unknown import path "golang.org/x/tools/cmd/goforward": cannot find module providing package golang.org/x/tools/cmd/goforward

~/src/golang.org/x/build$ go doc golang.org/x/tools/cmd/goforward | head -n 2
The goforward command adds forwarding declarations from one Go package to
another.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions