From 7b625d1f65a6224968d8668c1ae1b0730dabb605 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 20 Jul 2023 14:00:20 -0700 Subject: [PATCH] go/types, types2: make sure info recording is executed in test runs Issue #61486 causes a compiler crash but is not detected when running stand-alone type-checker tests because no types are recorded. Set up Config.Info map with all maps when when running local tests so that type/object recording code is executed during local tests. For #61486. Change-Id: I8eb40c8525dac3da65db0dc7e0e654842713b9a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/511657 Auto-Submit: Robert Griesemer Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Alan Donovan TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/check_test.go | 12 +++++++++++- src/go/types/check_test.go | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go index 8cb3000501c1d8..94dfda7d33b7e2 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -163,7 +163,17 @@ func testFiles(t *testing.T, filenames []string, srcs [][]byte, colDelta uint, m opt(&conf) } - conf.Check(pkgName, files, nil) + // Provide Config.Info with all maps so that info recording is tested. + info := Info{ + Types: make(map[syntax.Expr]TypeAndValue), + Instances: make(map[*syntax.Name]Instance), + Defs: make(map[*syntax.Name]Object), + Uses: make(map[*syntax.Name]Object), + Implicits: make(map[syntax.Node]Object), + Selections: make(map[*syntax.SelectorExpr]*Selection), + Scopes: make(map[syntax.Node]*Scope), + } + conf.Check(pkgName, files, &info) if listErrors { return diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go index 9093a46a0a94a6..0841396f358793 100644 --- a/src/go/types/check_test.go +++ b/src/go/types/check_test.go @@ -178,7 +178,17 @@ func testFiles(t *testing.T, filenames []string, srcs [][]byte, manual bool, opt opt(&conf) } - conf.Check(pkgName, fset, files, nil) + // Provide Config.Info with all maps so that info recording is tested. + info := Info{ + Types: make(map[ast.Expr]TypeAndValue), + Instances: make(map[*ast.Ident]Instance), + Defs: make(map[*ast.Ident]Object), + Uses: make(map[*ast.Ident]Object), + Implicits: make(map[ast.Node]Object), + Selections: make(map[*ast.SelectorExpr]*Selection), + Scopes: make(map[ast.Node]*Scope), + } + conf.Check(pkgName, fset, files, &info) if listErrors { return