Extractor: tolerate ast.File structures without a package declaration

In earlier versions of golang/x/tools these would be omitted entirely; now they can result in ast.File structures whose ast.Package field is zero (NoPos), and in my experience these contain no information in their other fields either.
This commit is contained in:
Chris Smowton
2020-09-03 14:32:23 +01:00
parent af1be2f465
commit e386346a25

View File

@@ -379,6 +379,10 @@ func normalizedPath(ast *ast.File, fset *token.FileSet) string {
// extractFile extracts AST information for the given file
func extractFile(ast *ast.File, pkg *packages.Package, fdSem *semaphore) error {
fset := pkg.Fset
if ast.Package == token.NoPos {
log.Printf("Skipping extracting a file without a 'package' declaration")
return nil
}
path := normalizedPath(ast, fset)
fdSem.acquire(3)