go/analysis,go/ssa: initialize the types.Info.Instances map
Update a couple places where we should initialize the
types.Info.Instances map:
- The unitchecker may be used with analyzers that expect the Instances
map to be populated.
- go/ssa will eventually support instances.
Change-Id: Id3dafe57430e5710ee91215a9586b09a87470b15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/357757
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
diff --git a/go/analysis/unitchecker/unitchecker.go b/go/analysis/unitchecker/unitchecker.go
index 5424489..b539866 100644
--- a/go/analysis/unitchecker/unitchecker.go
+++ b/go/analysis/unitchecker/unitchecker.go
@@ -51,6 +51,7 @@
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/internal/analysisflags"
"golang.org/x/tools/go/analysis/internal/facts"
+ "golang.org/x/tools/internal/typeparams"
)
// A Config describes a compilation unit to be analyzed.
@@ -233,6 +234,8 @@
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
}
+ typeparams.InitInstanceInfo(info)
+
pkg, err := tc.Check(cfg.ImportPath, fset, files, info)
if err != nil {
if cfg.SucceedOnTypecheckFailure {
diff --git a/go/ssa/testmain.go b/go/ssa/testmain.go
index c4256d1..b748332 100644
--- a/go/ssa/testmain.go
+++ b/go/ssa/testmain.go
@@ -21,6 +21,8 @@
"os"
"strings"
"text/template"
+
+ "golang.org/x/tools/internal/typeparams"
)
// FindTests returns the Test, Benchmark, and Example functions
@@ -180,6 +182,7 @@
Scopes: make(map[ast.Node]*types.Scope),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
}
+ typeparams.InitInstanceInfo(info)
testmainPkg, err := conf.Check(path, prog.Fset, files, info)
if err != nil {
log.Fatalf("internal error type-checking %s: %v", path, err)