Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit e386346

Browse files
committed
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.
1 parent af1be2f commit e386346

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

extractor/extractor.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ func normalizedPath(ast *ast.File, fset *token.FileSet) string {
379379
// extractFile extracts AST information for the given file
380380
func extractFile(ast *ast.File, pkg *packages.Package, fdSem *semaphore) error {
381381
fset := pkg.Fset
382+
if ast.Package == token.NoPos {
383+
log.Printf("Skipping extracting a file without a 'package' declaration")
384+
return nil
385+
}
382386
path := normalizedPath(ast, fset)
383387

384388
fdSem.acquire(3)

0 commit comments

Comments
 (0)