aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-08-04 18:02:43 -0700
committerRobert Griesemer <gri@golang.org>2010-08-04 18:02:43 -0700
commitd9e2631b53395fd3128f62cc621f2b1ed206a109 (patch)
treee7fe3892815c4fd29df214abc1f3094a3911ea9d
parented8c23149ffa467b8154c4009517499abdacc20e (diff)
downloadgo-d9e2631b53395fd3128f62cc621f2b1ed206a109.tar.gz
go-d9e2631b53395fd3128f62cc621f2b1ed206a109.zip
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
-rw-r--r--src/pkg/go/parser/interface.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/pkg/go/parser/interface.go b/src/pkg/go/parser/interface.go
index e1ddb37c30..6d11a26669 100644
--- a/src/pkg/go/parser/interface.go
+++ b/src/pkg/go/parser/interface.go
@@ -147,16 +147,13 @@ func ParseFile(filename string, src interface{}, scope *ast.Scope, mode uint) (*
// bits are passed to ParseFile unchanged.
//
// 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.
//
-func ParseFiles(filenames []string, scope *ast.Scope, mode uint) (map[string]*ast.Package, os.Error) {
- pkgs := make(map[string]*ast.Package)
- var err 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)
for _, filename := range filenames {
- var src *ast.File
- src, err = ParseFile(filename, nil, scope, mode)
- if err == nil {
+ if src, err := ParseFile(filename, nil, scope, mode); err == nil {
name := src.Name.Name()
pkg, found := pkgs[name]
if !found {
@@ -164,10 +161,11 @@ func ParseFiles(filenames []string, scope *ast.Scope, mode uint) (map[string]*as
pkgs[name] = pkg
}
pkg.Files[filename] = src
+ } else if first == nil {
+ first = err
}
}
-
- return pkgs, err
+ return
}