From 003fde144ea55295b5c7e9bccc8c09c08ce976ed Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 7 Nov 2022 16:11:05 -0500 Subject: [PATCH] internal/gcimporter: use nondeprecated go/packages mode bits I meant to do this in the first CL, but was prevented by a bug which I have since reported and linked to from the code. Change-Id: I651e728c535cdeb0885eae4d510fda3c24518dcf Reviewed-on: https://go-review.googlesource.com/c/tools/+/448376 Auto-Submit: Alan Donovan gopls-CI: kokoro Reviewed-by: Robert Findley Run-TryBot: Alan Donovan TryBot-Result: Gopher Robot --- internal/gcimporter/shallow_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/gcimporter/shallow_test.go b/internal/gcimporter/shallow_test.go index 717cb87895..3d8c86a154 100644 --- a/internal/gcimporter/shallow_test.go +++ b/internal/gcimporter/shallow_test.go @@ -28,7 +28,10 @@ func TestShallowStd(t *testing.T) { // Load import graph of the standard library. // (No parsing or type-checking.) cfg := &packages.Config{ - Mode: packages.LoadImports, + Mode: packages.NeedImports | + packages.NeedName | + packages.NeedFiles | // see https://github.com/golang/go/issues/56632 + packages.NeedCompiledGoFiles, Tests: false, } pkgs, err := packages.Load(cfg, "std") @@ -111,7 +114,6 @@ func typecheck(t *testing.T, ppkg *packages.Package) { insert func(p *types.Package, name string) importMap = make(map[string]*types.Package) // keys are PackagePaths ) - loadFromExportData := func(imp *packages.Package) (*types.Package, error) { data := []byte(imp.ExportFile) return gcimporter.IImportShallow(fset, importMap, data, imp.PkgPath, insert) @@ -125,13 +127,12 @@ func typecheck(t *testing.T, ppkg *packages.Package) { if err != nil { t.Fatalf("unmarshal: %v", err) } - obj := imported.Scope().Lookup(name) - if obj == nil { - t.Fatalf("lookup %q.%s failed", imported.Path(), name) - } if imported != p { t.Fatalf("internal error: inconsistent packages") } + if obj := imported.Scope().Lookup(name); obj == nil { + t.Fatalf("lookup %q.%s failed", imported.Path(), name) + } } cfg := &types.Config{