diff --git a/src/cmd/compile/internal/types2/check.go b/src/cmd/compile/internal/types2/check.go index 68cfdb5d1e..43ad4ee67f 100644 --- a/src/cmd/compile/internal/types2/check.go +++ b/src/cmd/compile/internal/types2/check.go @@ -315,6 +315,13 @@ func (check *Checker) initFiles(files []*syntax.File) { check.objPath = nil check.cleaners = nil + // We must initialize usedVars and usedPkgNames both here and in NewChecker, + // because initFiles is not called in the CheckExpr or Eval codepaths, yet we + // want to free this memory at the end of Files ('used' predicates are + // only needed in the context of a given file). + check.usedVars = make(map[*Var]bool) + check.usedPkgNames = make(map[*PkgName]bool) + // determine package name and collect valid files pkg := check.pkg for _, file := range files { diff --git a/src/go/types/check.go b/src/go/types/check.go index eda0a58ad0..a60a1adfd9 100644 --- a/src/go/types/check.go +++ b/src/go/types/check.go @@ -339,6 +339,13 @@ func (check *Checker) initFiles(files []*ast.File) { check.objPath = nil check.cleaners = nil + // We must initialize usedVars and usedPkgNames both here and in NewChecker, + // because initFiles is not called in the CheckExpr or Eval codepaths, yet we + // want to free this memory at the end of Files ('used' predicates are + // only needed in the context of a given file). + check.usedVars = make(map[*Var]bool) + check.usedPkgNames = make(map[*PkgName]bool) + // determine package name and collect valid files pkg := check.pkg for _, file := range files {