1
0
mirror of https://github.com/golang/go synced 2024-09-29 17:24:34 -06:00

cmd/doc, go/parser: fix merging comments in -src mode

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
This commit is contained in:
Ivan Trubach 2019-12-12 15:46:37 +03:00
parent 044eea9c3f
commit 654fb45042

View File

@ -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
}