]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: call mustParse when using mustTypecheck
authorRobert Griesemer <gri@golang.org>
Thu, 27 Apr 2023 23:07:11 +0000 (16:07 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 28 Apr 2023 16:30:57 +0000 (16:30 +0000)
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 <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>

src/cmd/compile/internal/types2/api_test.go
src/go/types/api_test.go

index e824f56fae76dc53d770cdd9fb36042f00e53beb..dcd4d72328e0f383cad189347f5db5145a84f9a9 100644 (file)
@@ -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
        }
index 7a8c63a43b8b5be6b1e665bf3c84bb298117ae25..2d0df43263e6df1c59e829834d7a8f5ed7fa085c 100644 (file)
@@ -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
        }