aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/exp
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2013-02-26 14:33:24 -0800
committerRobert Griesemer <gri@golang.org>2013-02-26 14:33:24 -0800
commit60066754fd6d080e6f0b08d88369beea4b54b801 (patch)
tree2a06b16a70871ccfe54f47bc56ae994c6d1ec006 /src/pkg/exp
parent98d44d140d7abde9fdfbdbf7adec5be7bb0892ce (diff)
downloadgo-60066754fd6d080e6f0b08d88369beea4b54b801.tar.xz
go/types: be more robust in presence of multiple errors
- better documentation of Check - better handling of (explicit) internal panics - gotype: don't stop after 1st error R=adonovan, r CC=golang-dev https://golang.org/cl/7406052
Diffstat (limited to 'src/pkg/exp')
-rw-r--r--src/pkg/exp/gotype/gotype.go33
-rw-r--r--src/pkg/exp/gotype/gotype_test.go6
2 files changed, 30 insertions, 9 deletions
diff --git a/src/pkg/exp/gotype/gotype.go b/src/pkg/exp/gotype/gotype.go
index a9042ee05b..db673f30ee 100644
--- a/src/pkg/exp/gotype/gotype.go
+++ b/src/pkg/exp/gotype/gotype.go
@@ -31,7 +31,7 @@ var (
printAST = flag.Bool("ast", false, "print AST")
)
-var exitCode = 0
+var errorCount int
func usage() {
fmt.Fprintf(os.Stderr, "usage: gotype [flags] [path ...]\n")
@@ -41,7 +41,11 @@ func usage() {
func report(err error) {
scanner.PrintError(os.Stderr, err)
- exitCode = 2
+ if list, ok := err.(scanner.ErrorList); ok {
+ errorCount += len(list)
+ return
+ }
+ errorCount++
}
// parse returns the AST for the Go source src.
@@ -163,10 +167,25 @@ func processFiles(filenames []string, allFiles bool) {
}
func processPackage(fset *token.FileSet, files []*ast.File) {
- _, err := types.Check(fset, files)
- if err != nil {
- report(err)
+ type bailout struct{}
+ ctxt := types.Context{
+ Error: func(err error) {
+ if !*allErrors && errorCount >= 10 {
+ panic(bailout{})
+ }
+ report(err)
+ },
}
+
+ defer func() {
+ switch err := recover().(type) {
+ case nil, bailout:
+ default:
+ panic(err)
+ }
+ }()
+
+ ctxt.Check(fset, files)
}
func main() {
@@ -180,5 +199,7 @@ func main() {
processFiles(flag.Args(), true)
}
- os.Exit(exitCode)
+ if errorCount > 0 {
+ os.Exit(2)
+ }
}
diff --git a/src/pkg/exp/gotype/gotype_test.go b/src/pkg/exp/gotype/gotype_test.go
index 03c114013a..9e2fad0154 100644
--- a/src/pkg/exp/gotype/gotype_test.go
+++ b/src/pkg/exp/gotype/gotype_test.go
@@ -13,7 +13,7 @@ import (
)
func runTest(t *testing.T, path string) {
- exitCode = 0
+ errorCount = 0
*recursive = false
if suffix := ".go"; strings.HasSuffix(path, suffix) {
@@ -41,8 +41,8 @@ func runTest(t *testing.T, path string) {
processFiles(files, true)
}
- if exitCode != 0 {
- t.Errorf("processing %s failed: exitCode = %d", path, exitCode)
+ if errorCount > 0 {
+ t.Errorf("processing %s failed: %d errors", path, errorCount)
}
}