]> Cypherpunks repositories - gostls13.git/commit
cmd/go/internal/list: make a copy of the package before zeroing fields
authorMichael Matloob <matloob@golang.org>
Wed, 3 Jan 2024 19:23:49 +0000 (14:23 -0500)
committerMichael Matloob <matloob@golang.org>
Mon, 29 Jan 2024 19:35:47 +0000 (19:35 +0000)
commita64d5be9125c9508d5cf4ff1a869ec2316097f92
treefd4e23551ca9de3d693fe5692fc6717224c42c6a
parente076c1b897b30648db794b66fd10929fe9a9852e
cmd/go/internal/list: make a copy of the package before zeroing fields

go list -json=<fields> zeroes out the fields in the package struct
that aren't specified. The problem with this is that some of the fields
have references into other fields: specifically, the NoGoError's
Error() function accesses the package struct's Dir field, so if we
clear it out the error will just print out "no Go files in" without a
directory. Instead, make a copy of the package struct before we zero
out the fields so the original values are still there.

For #64946

Change-Id: I95103e91fa0782bb23a86a965d5eb87cb12654c6
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/553795
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/internal/list/list.go
src/cmd/go/testdata/script/list_json_issue64946.txt [new file with mode: 0644]