Skip to content

Commit 307976d

Browse files
committed
go/packages: issue error if 'go list' on PATH is too new
An application that links in version 1.18 of (say) go/types cannot process Go source files reported by version 1.19 of 'go list'. There is no way to tell go list to behave as if it was go1.18, so for now we proceed with parsing/typechecking but, in case of errors, we issue an additional informative diagnostic. Fixes golang/go#55883 Fixes golang/go#55045 Updates golang/go#50825 Updates golang/go#52078 Change-Id: I5fd99b09742c136f4db7f71d2a75e4cdb730460d Reviewed-on: https://go-review.googlesource.com/c/tools/+/435356 gopls-CI: kokoro <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Alan Donovan <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Zvonimir Pavlinovic <[email protected]>
1 parent f5bec80 commit 307976d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

internal/gocommand/version.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ import (
1010
"strings"
1111
)
1212

13-
// GoVersion checks the go version by running "go list" with modules off.
14-
// It returns the X in Go 1.X.
13+
// GoVersion reports the minor version number of the highest release
14+
// tag built into the go command on the PATH.
15+
//
16+
// Note that this may be higher than the version of the go tool used
17+
// to build this application, and thus the versions of the standard
18+
// go/{scanner,parser,ast,types} packages that are linked into it.
19+
// In that case, callers should either downgrade to the version of
20+
// go used to build the application, or report an error that the
21+
// application is too old to use the go command on the PATH.
1522
func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error) {
1623
inv.Verb = "list"
1724
inv.Args = []string{"-e", "-f", `{{context.ReleaseTags}}`, `--`, `unsafe`}
@@ -38,7 +45,7 @@ func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error) {
3845
if len(stdout) < 3 {
3946
return 0, fmt.Errorf("bad ReleaseTags output: %q", stdout)
4047
}
41-
// Split up "[go1.1 go1.15]"
48+
// Split up "[go1.1 go1.15]" and return highest go1.X value.
4249
tags := strings.Fields(stdout[1 : len(stdout)-2])
4350
for i := len(tags) - 1; i >= 0; i-- {
4451
var version int

0 commit comments

Comments
 (0)