diff --git a/src/go/parser/interface.go b/src/go/parser/interface.go index cc7e455c4db..d5c18a9e2db 100644 --- a/src/go/parser/interface.go +++ b/src/go/parser/interface.go @@ -140,7 +140,7 @@ func ParseDir(fset *token.FileSet, path string, filter func(fs.FileInfo) bool, m pkgs = make(map[string]*ast.Package) for _, d := range list { - if strings.HasSuffix(d.Name(), ".go") && (filter == nil || filter(d)) { + if !d.IsDir() && strings.HasSuffix(d.Name(), ".go") && (filter == nil || filter(d)) { filename := filepath.Join(path, d.Name()) if src, err := ParseFile(fset, filename, nil, mode); err == nil { name := src.Name.Name diff --git a/src/go/parser/parser_test.go b/src/go/parser/parser_test.go index 7193a329fe9..a4f882d3688 100644 --- a/src/go/parser/parser_test.go +++ b/src/go/parser/parser_test.go @@ -82,6 +82,14 @@ func TestParseDir(t *testing.T) { } } +func TestIssue42951(t *testing.T) { + path := "./testdata/issue42951" + _, err := ParseDir(token.NewFileSet(), path, nil, 0) + if err != nil { + t.Errorf("ParseDir(%s): %v", path, err) + } +} + func TestParseExpr(t *testing.T) { // just kicking the tires: // a valid arithmetic expression diff --git a/src/go/parser/testdata/issue42951/not_a_file.go/invalid.go b/src/go/parser/testdata/issue42951/not_a_file.go/invalid.go new file mode 100644 index 00000000000..bb698be11cd --- /dev/null +++ b/src/go/parser/testdata/issue42951/not_a_file.go/invalid.go @@ -0,0 +1 @@ +This file should not be parsed by ParseDir.