-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/packages: ensure that types.Sizes is correct
This change ensures that types.Sizes information can be computed from compiler+GOARCH if it is needed; if not, it causes the Load to fail. This fixes a crash in gopls whereby a bad GOARCH causes the types.Sizes to be silently nil, in violation of the Packages.TypesSizes contract. Gopls would then dereference this nil. The problem only manifests with a file=foo.go query, as this suppresses go list's usual eager check for valid GOOS/GOARCH during its build tag computation. gopls relies on the file=... mode as a fall back. Note that this change reverts my earlier doc change today that allowed TypesSizes to be nil if unknown. This was the wrong fix, as it creates both a nil-dereference hazard (the original bug), plus, if the nil Sizes is fed to go/types.Config, it would trigger the default (wrong) size computation. (This is less significant to gopls because in file=... mode, size errors are the least of your type-error worries, but still...) Plus, a test. Also: simplify two trivially true conditions in the packages.Load control flow. Fixes golang/go#63701 Fixes golang/vscode-go#3021 Change-Id: I8d519d0d8a8c7bce6b3206a8116a150d37e74e45 Reviewed-on: https://go-review.googlesource.com/c/tools/+/537118 Reviewed-by: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
- Loading branch information
Showing
3 changed files
with
75 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters