Skip to content

Commit

Permalink
cmd/doc, go/parser: fix merging comments in -src mode
Browse files Browse the repository at this point in the history
This commit fixes go doc -src mode that vomits comments from random files if
filesystem does not sort files by name. The issue was with parse.ParseDir
using the Readdir order of files, which varies between platforms and filesystem
implementations. Another option is to merge comments using token.FileSet.Iterate
order in cmd/doc, but since ParseDir is mostly used in go doc, I’ve opted for
smaller change because it’s unlikely to break other uses or cause any perfomance
issues.

Example (macOS APFS): go doc -src net.ListenPacket
  • Loading branch information
tie committed Dec 12, 2019
1 parent 044eea9 commit 654fb45
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/go/parser/interface.go
Expand Up @@ -133,13 +133,7 @@ func ParseFile(fset *token.FileSet, filename string, src interface{}, mode Mode)
// first error encountered are returned.
//
func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, mode Mode) (pkgs map[string]*ast.Package, first error) {
fd, err := os.Open(path)
if err != nil {
return nil, err
}
defer fd.Close()

list, err := fd.Readdir(-1)
list, err := ioutil.ReadDir(path)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 654fb45

Please sign in to comment.