Commit d9e2631b authored by Robert Griesemer's avatar Robert Griesemer

go/parser.ParseFiles: don't override error (to nil) if there is one

Also: Return first instead of last error as that seems more useful.

R=r
CC=golang-dev
https://golang.org/cl/1897050
parent ed8c2314
...@@ -147,16 +147,13 @@ func ParseFile(filename string, src interface{}, scope *ast.Scope, mode uint) (* ...@@ -147,16 +147,13 @@ func ParseFile(filename string, src interface{}, scope *ast.Scope, mode uint) (*
// bits are passed to ParseFile unchanged. // bits are passed to ParseFile unchanged.
// //
// Files with parse errors are ignored. In this case the map of packages may // Files with parse errors are ignored. In this case the map of packages may
// be incomplete (missing packages and/or incomplete packages) and the last // be incomplete (missing packages and/or incomplete packages) and the first
// error encountered is returned. // error encountered is returned.
// //
func ParseFiles(filenames []string, scope *ast.Scope, mode uint) (map[string]*ast.Package, os.Error) { func ParseFiles(filenames []string, scope *ast.Scope, mode uint) (pkgs map[string]*ast.Package, first os.Error) {
pkgs := make(map[string]*ast.Package) pkgs = make(map[string]*ast.Package)
var err os.Error
for _, filename := range filenames { for _, filename := range filenames {
var src *ast.File if src, err := ParseFile(filename, nil, scope, mode); err == nil {
src, err = ParseFile(filename, nil, scope, mode)
if err == nil {
name := src.Name.Name() name := src.Name.Name()
pkg, found := pkgs[name] pkg, found := pkgs[name]
if !found { if !found {
...@@ -164,10 +161,11 @@ func ParseFiles(filenames []string, scope *ast.Scope, mode uint) (map[string]*as ...@@ -164,10 +161,11 @@ func ParseFiles(filenames []string, scope *ast.Scope, mode uint) (map[string]*as
pkgs[name] = pkg pkgs[name] = pkg
} }
pkg.Files[filename] = src pkg.Files[filename] = src
} else if first == nil {
first = err
} }
} }
return
return pkgs, err
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment