Skip to content

Commit 0b45163

Browse files
findleyrgopherbot
authored andcommitted
gopls/internal/cache: use language versions when validating Go version
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]>
1 parent 3c49bb7 commit 0b45163

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

gopls/internal/cache/check.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ func validGoVersion(goVersion string) bool {
16631663
return false // malformed version string
16641664
}
16651665

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This test checks that gopls successfully suppresses loopclosure diagnostics
2+
when the go.mod go version is set to a 1.22 toolchain version (1.22.x).
3+
4+
In golang/go#66876, gopls failed to handle this correctly.
5+
6+
-- flags --
7+
-min_go=go1.22
8+
9+
-- go.mod --
10+
module example.com/loopclosure
11+
12+
go 1.22.0
13+
14+
-- p.go --
15+
package main
16+
17+
var x int //@loc(x, "x")
18+
19+
func main() {
20+
// Verify that type checking actually succeeded by jumping to
21+
// an arbitrary definition.
22+
_ = x //@def("x", x)
23+
24+
for i := range 10 {
25+
go func() { println(i) }()
26+
}
27+
}

0 commit comments

Comments
 (0)