Skip to content

cmd/go: versioned package doc shows unexpected doc for stdlib #81670

Open

Description

@hyangah

Go version

$ go1.27.1 version go version go1.27.1 linux/amd64

Output of go env in your module/workspace:

$ go1.27.1 env -changed
$

What did you do?

$ go1.27.1 doc encoding/json/v2@go1.19.0

What did you see happen?

$ go1.27.1 doc encoding/json/v2@go1.19.0
package json // import "encoding/json/v2"

Package json implements semantic processing of JSON as specified in RFC 8259.
JSON is a simple data interchange format that can represent primitive data types
....

What did you expect to see?

Error that the package doesn't exist

Activity

  1. prattmic commented on Sep 29, 2026

    @prattmic
    Member

    cc @golang/command-line

  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Sep 29, 2026
  3. added this to the Backlog milestone on Oct 6, 2026
  4. matloob commented on Oct 6, 2026

    @matloob
    Contributor

    Sounds like we should just reject pkg@version syntax for stdlib packages.

  5. hyangah commented on Oct 6, 2026

    @hyangah
    ContributorAuthor

    Or, exec GOTOOLCHAIN=go1.x.y go doc <pkg>?

  6. hridhinvarkeyjoseph commented on Oct 6, 2026

    @hridhinvarkeyjoseph

    I looked into this, and I think the cause is in parseArgs in cmd/go/internal/doc/doc.go, not in the versioned load itself.

    For go doc encoding/json/v2@go1.19.0, importPkg calls loadVersioned, and load.PackagesAndErrorsOutsideModule already rejects it with argument must not be a package in the standard library. But that error is dropped: the single-argument path then falls into the loop that splits the argument at periods, and that loop calls loadPackage(ctx, loader, arg[0:period]), which loads the package without the version. For a standard library package that succeeds from GOROOT, so the current docs are printed. The same loop is reached for pkg.Symbol@version, so the version is ignored there too.

    Following @matloob's suggestion to reject @version for standard library packages, I'd like to send a fix that makes that loop use importPkg (versioned when a version is given), so the existing error is reported:

    go: encoding/json/v2@go1.19.0: argument must not be a package in the standard library
    

    with a script test in cmd/go/testdata/script. Does that direction sound right, or would you prefer the GOTOOLCHAIN approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions