-
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.
gopls/internal/analysis/stdversion: suppress before go1.21
This change causes the stdversion checker not to report any diagnostics in modules with go versons before go1.21, because the semantics of the go declaration were not clearly defined to correspond to toolchain requirements at that point. Also, those Go versions are now unsupported, so reporting diagnostics just creates unnecessary churn. Updates golang/go#46136 Change-Id: I323f704c4d4f1f0fe5fc8b5680824bc07d3c4112 Reviewed-on: https://go-review.googlesource.com/c/tools/+/570140 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
- Loading branch information
Showing
6 changed files
with
141 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,101 @@ | ||
Test of "too new" diagnostics from the stdversion analyzer. | ||
|
||
This test references go1.21 symbols from std. | ||
This test references go1.21 and go1.22 symbols from std. | ||
|
||
It uses a txtar file due to golang/go#37054. | ||
|
||
See also gopls/internal/test/marker/testdata/diagnostics/stdversion.txt | ||
which runs the same test within the gopls analysis driver, to ensure | ||
coverage of per-file Go version support. | ||
|
||
-- go.work -- | ||
use . | ||
use ./sub | ||
|
||
-- go.mod -- | ||
module example.com | ||
|
||
go 1.19 | ||
go 1.21 | ||
|
||
-- a/a.go -- | ||
package a | ||
|
||
import ( | ||
"context" | ||
"go/types" | ||
"time" | ||
) | ||
import "go/types" | ||
|
||
func _() { | ||
time.Now() // ok: defined by go1.0 | ||
|
||
context.Cause(nil) // want `context.Cause requires go1.20 or later \(module is go1.19\)` | ||
// old package-level type | ||
var _ types.Info // ok: defined by go1.0 | ||
|
||
context.WithDeadlineCause(nil, time.Time{}, nil) // want `context.WithDeadlineCause requires go1.21 or later \(module is go1.19\)` | ||
// new field of older type | ||
_ = new(types.Info).FileVersions // want `types.FileVersions requires go1.22 or later \(module is go1.21\)` | ||
|
||
// GoVersion is a new method of an older type. | ||
new(types.Package).GoVersion() // want `types.GoVersion requires go1.21 or later \(module is go1.19\)` | ||
} | ||
// new method of older type | ||
new(types.Info).PkgNameOf // want `types.PkgNameOf requires go1.22 or later \(module is go1.21\)` | ||
|
||
-- a/selections.go -- | ||
package a | ||
|
||
import ( | ||
"go/ast" // for File.FileEnd field (go1.20) | ||
"time" // for Time.Compare method (go1.20) | ||
"log/slog" // for slog.Logger and its Info method (both go1.21) | ||
) | ||
|
||
func _() { | ||
_ = new(ast.File).FileEnd // want `ast.FileEnd requires go1.20 or later \(module is go1.19\)` | ||
time.Now().Compare(time.Now()) // want `time.Compare requires go1.20 or later \(module is go1.19\)` | ||
// new package-level type | ||
var a types.Alias // want `types.Alias requires go1.22 or later \(module is go1.21\)` | ||
|
||
var log slog.Logger // want `slog.Logger requires go1.21 or later \(module is go1.19\)` | ||
log.Info("") // no diagnostic | ||
// new method of new type | ||
a.Underlying() // no diagnostic | ||
} | ||
|
||
-- sub/go.mod -- | ||
module example.com/sub | ||
|
||
go 1.20 | ||
go 1.21 | ||
|
||
-- sub/sub.go -- | ||
package sub | ||
|
||
import ( | ||
"context" | ||
"go/types" | ||
"time" | ||
) | ||
import "go/types" | ||
|
||
func _() { | ||
time.Now() // ok: defined by go1.0 | ||
// old package-level type | ||
var _ types.Info // ok: defined by go1.0 | ||
|
||
context.Cause(nil) // ok: go.mod requires 1.20 | ||
// new field of older type | ||
_ = new(types.Info).FileVersions // want `types.FileVersions requires go1.22 or later \(module is go1.21\)` | ||
|
||
context.WithDeadlineCause(nil, time.Time{}, nil) // want `context.WithDeadlineCause requires go1.21 or later \(module is go1.20\)` | ||
// new method of older type | ||
new(types.Info).PkgNameOf // want `types.PkgNameOf requires go1.22 or later \(module is go1.21\)` | ||
|
||
// GoVersion is a new (go1.21) method of an old (go1.0) type. | ||
new(types.Package).GoVersion() // want `types.GoVersion requires go1.21 or later \(module is go1.20\)` | ||
// new package-level type | ||
var a types.Alias // want `types.Alias requires go1.22 or later \(module is go1.21\)` | ||
|
||
// new method of new type | ||
a.Underlying() // no diagnostic | ||
} | ||
|
||
invalid syntax // exercise RunDespiteErrors | ||
|
||
-- sub/tagged.go -- | ||
//go:build go1.21 | ||
//go:build go1.22 | ||
|
||
package sub | ||
|
||
import ( | ||
"context" | ||
"go/types" | ||
"time" | ||
) | ||
import "go/types" | ||
|
||
func _() { | ||
time.Now() // ok: defined by go1.0 | ||
// old package-level type | ||
var _ types.Info | ||
|
||
// new field of older type | ||
_ = new(types.Info).FileVersions | ||
|
||
context.Cause(nil) // ok: go.mod requires 1.20 | ||
// new method of older type | ||
new(types.Info).PkgNameOf | ||
|
||
context.WithDeadlineCause(nil, time.Time{}, nil) // ok: file requires go1.21 | ||
// new package-level type | ||
var a types.Alias | ||
|
||
new(types.Package).GoVersion() // ok: file requires go1.21 | ||
// new method of new type | ||
a.Underlying() | ||
} | ||
|
||
-- old/go.mod -- | ||
module example.com/old | ||
|
||
go 1.5 | ||
|
||
-- old/old.go -- | ||
package old | ||
|
||
import "go/types" | ||
|
||
var _ types.Alias // no diagnostic: go.mod is too old for us to care |
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
Oops, something went wrong.