| Test of "too new" diagnostics from the stdversion analyzer. |
| |
| This test references go1.21 symbols from std, but the analyzer itself |
| depends on the the go1.22 behavior of versions.FileVersion. |
| |
| See also gopls/internal/analysis/stdversion/testdata/test.txtar, |
| which runs the same test in the analysistest framework. |
| |
| -- flags -- |
| -min_go=go1.22 |
| |
| -- go.mod -- |
| module example.com |
| |
| go 1.19 |
| |
| -- a/a.go -- |
| package a |
| |
| import ( |
| "context" |
| "time" |
| ) |
| |
| func _() { |
| time.Now() // ok: defined by go1.0 |
| |
| context.Cause(nil) //@ diag("Cause", re`context.Cause requires go1.20 or later \(module is go1.19\)`) |
| |
| context.WithDeadlineCause(nil, time.Time{}, nil) //@ diag("WithDeadlineCause", re`context.WithDeadlineCause requires go1.21 or later \(module is go1.19\)`) |
| } |
| |
| -- 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 //@ diag("FileEnd", re`ast.FileEnd requires go1.20 or later \(module is go1.19\)`) |
| time.Now().Compare(time.Now()) //@ diag("Compare", re`time.Compare requires go1.20 or later \(module is go1.19\)`) |
| |
| var log slog.Logger //@ diag("Logger", re`slog.Logger requires go1.21 or later \(module is go1.19\)`) |
| log.Info("") // no diagnostic |
| } |
| |
| -- sub/go.mod -- |
| module example.com/sub |
| |
| go 1.20 |
| |
| -- sub/sub.go -- |
| package sub |
| |
| import ( |
| "context" |
| "time" |
| ) |
| |
| func _() { |
| time.Now() // ok: defined by go1.0 |
| |
| context.Cause(nil) // ok: go.mod requires 1.20 |
| |
| context.WithDeadlineCause(nil, time.Time{}, nil) //@ diag("WithDeadlineCause", re`context.WithDeadlineCause requires go1.21 or later \(module is go1.20\)`) |
| } |
| |
| -- sub/tagged.go -- |
| //go:build go1.21 |
| |
| package sub |
| |
| import ( |
| "context" |
| "time" |
| ) |
| |
| func _() { |
| time.Now() // ok: defined by go1.0 |
| |
| context.Cause(nil) // ok: go.mod requires 1.20 |
| |
| context.WithDeadlineCause(nil, time.Time{}, nil) // ok: file requires go1.21 |
| } |