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 <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2022-11-07 16:11:05 -05:00 committed by Gopher Robot
parent 50506576b8
commit 003fde144e
1 changed files with 7 additions and 6 deletions

View File

@ -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{