You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/go: versioned package doc shows unexpected doc for stdlib #81670
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
....
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?
Activity
gabyhelp commentedon Sep 22, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
prattmic commentedon Sep 29, 2026
cc @golang/command-line
matloob commentedon Oct 6, 2026
Sounds like we should just reject pkg@version syntax for stdlib packages.
hyangah commentedon Oct 6, 2026
Or, exec
GOTOOLCHAIN=go1.x.y go doc <pkg>?hridhinvarkeyjoseph commentedon Oct 6, 2026
I looked into this, and I think the cause is in
parseArgsincmd/go/internal/doc/doc.go, not in the versioned load itself.For
go doc encoding/json/v2@go1.19.0,importPkgcallsloadVersioned, andload.PackagesAndErrorsOutsideModulealready rejects it withargument 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 callsloadPackage(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 forpkg.Symbol@version, so the version is ignored there too.Following @matloob's suggestion to reject
@versionfor standard library packages, I'd like to send a fix that makes that loop useimportPkg(versioned when a version is given), so the existing error is reported:with a script test in
cmd/go/testdata/script. Does that direction sound right, or would you prefer theGOTOOLCHAINapproach?