diff --git a/go/loader/loader.go b/go/loader/loader.go index 98df7aad..4503dd9e 100644 --- a/go/loader/loader.go +++ b/go/loader/loader.go @@ -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 } diff --git a/oracle/oracle.go b/oracle/oracle.go index 4cdd2eca..65ac9edd 100644 --- a/oracle/oracle.go +++ b/oracle/oracle.go @@ -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) {} }