oracle: disable parser bailout

This change sets ParserMode=AllErrors so that the parser is never
allowed to discard the AST and use a dummy one just because it saw too
many errors.

Also, change (*loader.Program).PathEnclosingInterval so that other
clients that forget to set this flag don't panic while calling
fset.File(f.Pos()).Base() on an ast.File f with no position info.

Change-Id: Ie544f169d367d2aa85426212b27063dc72e36fb1
Reviewed-on: https://go-review.googlesource.com/10290
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2015-05-20 15:58:44 -04:00
parent 500e956000
commit 3d1847243e
2 changed files with 10 additions and 0 deletions

View File

@ -313,6 +313,12 @@ func (conf *Config) addImport(path string, tests bool) {
func (prog *Program) PathEnclosingInterval(start, end token.Pos) (pkg *PackageInfo, path []ast.Node, exact bool) {
for _, info := range prog.AllPackages {
for _, f := range info.Files {
if f.Pos() == token.NoPos {
// This can happen if the parser saw
// too many errors and bailed out.
// (Use parser.AllErrors to prevent that.)
continue
}
if !tokenFileContainsPos(prog.Fset.File(f.Pos()), start) {
continue
}

View File

@ -23,6 +23,7 @@ import (
"fmt"
"go/ast"
"go/build"
"go/parser"
"go/token"
"io"
"path/filepath"
@ -282,6 +283,9 @@ func allowErrors(lconf *loader.Config) {
ctxt.CgoEnabled = false
lconf.Build = &ctxt
lconf.AllowErrors = true
// AllErrors makes the parser always return an AST instead of
// bailing out after 10 errors and returning an empty ast.File.
lconf.ParserMode = parser.AllErrors
lconf.TypeChecker.Error = func(err error) {}
}