From e386346a255ef86fc95654eda353062cd49d1229 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Thu, 3 Sep 2020 14:32:23 +0100 Subject: [PATCH] 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. --- extractor/extractor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extractor/extractor.go b/extractor/extractor.go index 1a69f141a52..13613c638ff 100644 --- a/extractor/extractor.go +++ b/extractor/extractor.go @@ -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)