diff --git a/pkg/golinters/goanalysis/runner_loadingpackage.go b/pkg/golinters/goanalysis/runner_loadingpackage.go index a5b5cccfeef7..0a9653b8d20c 100644 --- a/pkg/golinters/goanalysis/runner_loadingpackage.go +++ b/pkg/golinters/goanalysis/runner_loadingpackage.go @@ -121,15 +121,7 @@ func (lp *loadingPackage) loadFromSource(loadMode LoadMode) error { pkg.IllTyped = true - pkg.TypesInfo = &types.Info{ - Types: make(map[ast.Expr]types.TypeAndValue), - Instances: make(map[*ast.Ident]types.Instance), - Defs: make(map[*ast.Ident]types.Object), - Uses: make(map[*ast.Ident]types.Object), - Implicits: make(map[ast.Node]types.Object), - Scopes: make(map[ast.Node]*types.Scope), - Selections: make(map[*ast.SelectorExpr]*types.Selection), - } + pkg.TypesInfo = newTypesInfo() importer := func(path string) (*types.Package, error) { if path == unsafePkgName { diff --git a/pkg/golinters/goanalysis/runner_loadingpackage_ti.go b/pkg/golinters/goanalysis/runner_loadingpackage_ti.go new file mode 100644 index 000000000000..e165935b1dff --- /dev/null +++ b/pkg/golinters/goanalysis/runner_loadingpackage_ti.go @@ -0,0 +1,21 @@ +//go:build go1.17 && !go1.18 +// +build go1.17,!go1.18 + +package goanalysis + +import ( + "go/ast" + "go/types" +) + +func newTypesInfo() *types.Info { + return &types.Info{ + Types: make(map[ast.Expr]types.TypeAndValue), + Instances: make(map[*ast.Ident]types.Instance), + Defs: make(map[*ast.Ident]types.Object), + Uses: make(map[*ast.Ident]types.Object), + Implicits: make(map[ast.Node]types.Object), + Scopes: make(map[ast.Node]*types.Scope), + Selections: make(map[*ast.SelectorExpr]*types.Selection), + } +} diff --git a/pkg/golinters/goanalysis/runner_loadingpackage_ti_go117.go b/pkg/golinters/goanalysis/runner_loadingpackage_ti_go117.go new file mode 100644 index 000000000000..742cf5fdbc4b --- /dev/null +++ b/pkg/golinters/goanalysis/runner_loadingpackage_ti_go117.go @@ -0,0 +1,17 @@ +package goanalysis + +import ( + "go/ast" + "go/types" +) + +func newTypesInfo() *types.Info { + return &types.Info{ + Types: make(map[ast.Expr]types.TypeAndValue), + Defs: make(map[*ast.Ident]types.Object), + Uses: make(map[*ast.Ident]types.Object), + Implicits: make(map[ast.Node]types.Object), + Scopes: make(map[ast.Node]*types.Scope), + Selections: make(map[*ast.SelectorExpr]*types.Selection), + } +}