Skip to content

Commit

Permalink
gopls/internal/cache: fix crash in snapshot.Analyze with patch versions
Browse files Browse the repository at this point in the history
Fix the same crash as golang/go#66195, this time in Analyze: don't set
invalid Go versions on the types.Config.

The largest part of this change was writing a realistic test, since the
lack of a test for golang/go#66195 caused us to miss this additional
location. It was possible to create a test that worked, by using a flag
to select a go1.21 binary location.

For this test, it was required to move a couple additional integration
test preconditions into integration.Main (otherwise, the test would be
skipped due to the modified environment).

Fixes golang/go#66636

Change-Id: I24385474d4a6ebf6b7e9ae8f20948564bad3f55e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/576135
Auto-Submit: Robert Findley <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Apr 3, 2024
1 parent 2fe04db commit a13e64f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ var checkGoBuild struct {
err error
}

func hasTool(tool string) error {
// HasTool reports an error if the required tool is not available in PATH.
//
// For certain tools, it checks that the tool executable is correct.
func HasTool(tool string) error {
if tool == "cgo" {
enabled, err := cgoEnabled(false)
if err != nil {
Expand Down Expand Up @@ -198,7 +201,7 @@ func allowMissingTool(tool string) bool {
// NeedsTool skips t if the named tool is not present in the path.
// As a special case, "cgo" means "go" is present and can compile cgo programs.
func NeedsTool(t testing.TB, tool string) {
err := hasTool(tool)
err := HasTool(tool)
if err == nil {
return
}
Expand Down

0 comments on commit a13e64f

Please sign in to comment.