Skip to content

Commit 38d6db9

Browse files
committed
staticcheck: propagate Go version
1 parent de069cf commit 38d6db9

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

pkg/goanalysis/runner.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"go/token"
1616
"runtime"
1717
"sort"
18+
"strings"
1819
"sync"
1920

2021
"golang.org/x/exp/maps"
@@ -58,11 +59,12 @@ type runner struct {
5859
passToPkg map[*analysis.Pass]*packages.Package
5960
passToPkgGuard sync.Mutex
6061
sw *timeutils.Stopwatch
62+
goVersion string // TODO(ldez) temporary workaround
6163
}
6264

63-
func newRunner(prefix string, logger logutils.Log, pkgCache *pkgcache.Cache, loadGuard *load.Guard,
64-
loadMode LoadMode, sw *timeutils.Stopwatch,
65-
) *runner {
65+
func newRunner(prefix string, logger logutils.Log,
66+
pkgCache *pkgcache.Cache, loadGuard *load.Guard, loadMode LoadMode,
67+
sw *timeutils.Stopwatch, goVersion string) *runner {
6668
return &runner{
6769
prefix: prefix,
6870
log: logger,
@@ -71,6 +73,7 @@ func newRunner(prefix string, logger logutils.Log, pkgCache *pkgcache.Cache, loa
7173
loadMode: loadMode,
7274
passToPkg: map[*analysis.Pass]*packages.Package{},
7375
sw: sw,
76+
goVersion: goVersion,
7477
}
7578
}
7679

@@ -247,6 +250,7 @@ func (r *runner) analyze(pkgs []*packages.Package, analyzers []*analysis.Analyze
247250

248251
loadingPackages[pkg] = &loadingPackage{
249252
pkg: pkg,
253+
goVersion: "go" + strings.TrimPrefix(r.goVersion, "go"),
250254
imports: imports,
251255
isInitial: initialPkgs[pkg],
252256
log: r.log,

pkg/goanalysis/runner_loadingpackage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const unsafePkgName = "unsafe"
2323

2424
type loadingPackage struct {
2525
pkg *packages.Package
26+
goVersion string // TODO(ldez) temporary workaround
2627
imports map[string]*loadingPackage
2728
isInitial bool
2829
log logutils.Log
@@ -155,6 +156,7 @@ func (lp *loadingPackage) loadFromSource(loadMode LoadMode) error {
155156
Error: func(err error) {
156157
pkg.Errors = append(pkg.Errors, lp.convertError(err)...)
157158
},
159+
GoVersion: lp.goVersion, // TODO(ldez) temporary workaround
158160
}
159161
_ = types.NewChecker(tc, pkg.Fset, pkg.Types, pkg.TypesInfo).Files(pkg.Syntax)
160162
// Don't handle error here: errors are adding by tc.Error function.

pkg/goanalysis/runners.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ func runAnalyzers(cfg runAnalyzersConfig, lintCtx *linter.Context) ([]result.Iss
3636
const stagesToPrint = 10
3737
defer sw.PrintTopStages(stagesToPrint)
3838

39-
runner := newRunner(cfg.getName(), log, lintCtx.PkgCache, lintCtx.LoadGuard, cfg.getLoadMode(), sw)
39+
var goVersion string
40+
if lintCtx.Cfg != nil {
41+
goVersion = lintCtx.Cfg.Run.Go
42+
}
43+
44+
runner := newRunner(cfg.getName(), log, lintCtx.PkgCache, lintCtx.LoadGuard, cfg.getLoadMode(), sw, goVersion)
4045

4146
pkgs := lintCtx.Packages
4247
if cfg.useOriginalPackages() {

0 commit comments

Comments
 (0)