Skip to content

Commit

Permalink
gopls/internal/cache: use language versions when validating Go version
Browse files Browse the repository at this point in the history
The check in CL 576678 was comparing the release version, which is a
language version, with the contents of the go directive, which may be a
toolchain version. As a result, gopls detects go1.22 < go1.22.2, and
does not set types.Config.GoVersion. Normally this would be acceptable,
since go/types falls back on allowing all language features.
Unfortunately, [email protected] lacks CL 567635, and so the loopclosure
analyzer reports a diagnostic in this case.

Fix by comparing language versions.

Fixes golang/go#567635

Change-Id: I13747f19e48186105967b9c777de5ca34908545f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/579758
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Tim King <[email protected]>
(cherry picked from commit 429c9f0)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/581807
Auto-Submit: Robert Findley <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Apr 26, 2024
1 parent 3c49bb7 commit 0b45163
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ func validGoVersion(goVersion string) bool {
return false // malformed version string
}

if relVer := releaseVersion(); relVer != "" && versions.Before(relVer, goVersion) {
if relVer := releaseVersion(); relVer != "" && versions.Before(versions.Lang(relVer), versions.Lang(goVersion)) {
return false // 'go list' is too new for go/types
}

Expand Down
27 changes: 27 additions & 0 deletions gopls/internal/test/marker/testdata/fixedbugs/issue66876.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This test checks that gopls successfully suppresses loopclosure diagnostics
when the go.mod go version is set to a 1.22 toolchain version (1.22.x).

In golang/go#66876, gopls failed to handle this correctly.

-- flags --
-min_go=go1.22

-- go.mod --
module example.com/loopclosure

go 1.22.0

-- p.go --
package main

var x int //@loc(x, "x")

func main() {
// Verify that type checking actually succeeded by jumping to
// an arbitrary definition.
_ = x //@def("x", x)

for i := range 10 {
go func() { println(i) }()
}
}

0 comments on commit 0b45163

Please sign in to comment.