From 972774c4448f41826577304da0b5fd7d6936df4c Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 27 Apr 2023 16:07:11 -0700 Subject: [PATCH] go/types, types2: call mustParse when using mustTypecheck Syntactically incorrect source files may produce valid (but unexpected) syntax trees, leading to difficult to understand test failures. Make sure to call mustParse when we call mustTypecheck. Change-Id: I9f5ba3fe57ad3bbc16caabf285d2e7aeb5b9de0c Reviewed-on: https://go-review.googlesource.com/c/go/+/489995 Run-TryBot: Robert Griesemer TryBot-Result: Gopher Robot Reviewed-by: Robert Findley Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer --- src/cmd/compile/internal/types2/api_test.go | 8 +++++++- src/go/types/api_test.go | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/types2/api_test.go b/src/cmd/compile/internal/types2/api_test.go index e824f56fae..dcd4d72328 100644 --- a/src/cmd/compile/internal/types2/api_test.go +++ b/src/cmd/compile/internal/types2/api_test.go @@ -49,7 +49,13 @@ func typecheck(path, src string, conf *Config, info *Info) (*Package, error) { } func mustTypecheck(path, src string, conf *Config, info *Info) *Package { - pkg, err := typecheck(path, src, conf, info) + f := mustParse(path, src) + if conf == nil { + conf = &Config{ + Importer: defaultImporter(), + } + } + pkg, err := conf.Check(f.PkgName.Value, []*syntax.File{f}, info) if err != nil { panic(err) // so we don't need to pass *testing.T } diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index 7a8c63a43b..2d0df43263 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -52,7 +52,14 @@ func typecheck(path, src string, conf *Config, info *Info) (*Package, error) { } func mustTypecheck(path, src string, conf *Config, info *Info) *Package { - pkg, err := typecheck(path, src, conf, info) + fset := token.NewFileSet() + f := mustParse(fset, path, src) + if conf == nil { + conf = &Config{ + Importer: importer.Default(), + } + } + pkg, err := conf.Check(f.Name.Name, fset, []*ast.File{f}, info) if err != nil { panic(err) // so we don't need to pass *testing.T } -- 2.48.1