From 654fb450421266a0bb64518016944db22bd681e3 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Thu, 12 Dec 2019 15:46:37 +0300 Subject: [PATCH] cmd/doc, go/parser: fix merging comments in -src mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/go/parser/interface.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/go/parser/interface.go b/src/go/parser/interface.go index 500c98d4966..54f9d7b80ac 100644 --- a/src/go/parser/interface.go +++ b/src/go/parser/interface.go @@ -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 }