gopls/internal/lsp/cache: add debugging assertion for golang/go#60904
Updates golang/go#60904
Change-Id: Ia9f259716732705060a0d3675cd701c6c68a215f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/504695
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
diff --git a/gopls/internal/lsp/cache/check.go b/gopls/internal/lsp/cache/check.go
index 1b0844a..14877ff 100644
--- a/gopls/internal/lsp/cache/check.go
+++ b/gopls/internal/lsp/cache/check.go
@@ -541,14 +541,25 @@
thisPackage := types.NewPackage(string(m.PkgPath), string(m.Name))
getPackages := func(items []gcimporter.GetPackagesItem) error {
for i, item := range items {
+ var id PackageID
+ var pkg *types.Package
if item.Path == string(m.PkgPath) {
- items[i].Pkg = thisPackage
+ id = m.ID
+ pkg = thisPackage
} else {
- pkg, err := b.getImportPackage(ctx, impMap[item.Path])
+ id = impMap[item.Path]
+ var err error
+ pkg, err = b.getImportPackage(ctx, id)
if err != nil {
return err
}
- items[i].Pkg = pkg
+ }
+ items[i].Pkg = pkg
+
+ // debugging issue #60904
+ if pkg.Name() != item.Name {
+ return bug.Errorf("internal error: package name is %q, want %q (id=%q, path=%q) (see issue #60904)",
+ pkg.Name(), item.Name, id, item.Path)
}
}
return nil