1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:54:59 -07:00

go/internal/gcimporter: return (possibly incomplete) package in case of error

For #16088.

Change-Id: Ib38bda06a5c5d110ca86510043775c5cf229e6a8
Reviewed-on: https://go-review.googlesource.com/37756
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2017-03-03 13:42:41 -08:00
parent 63f8cca95b
commit d8485ee2e7

View File

@ -47,12 +47,13 @@ type importer struct {
// and returns the number of bytes consumed and a reference to the package.
// If the export data version is not recognized or the format is otherwise
// compromised, an error is returned.
func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, _ *types.Package, err error) {
func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) {
// catch panics and return them as errors
defer func() {
if e := recover(); e != nil {
// The package (filename) causing the problem is added to this
// error by a wrapper in the caller (Import in gcimporter.go).
// Return a (possibly nil or incomplete) package unchanged (see #16088).
err = fmt.Errorf("cannot import, possibly version skew (%v) - reinstall package", e)
}
}()
@ -117,7 +118,7 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
p.typList = append(p.typList, predeclared...)
// read package data
pkg := p.pkg()
pkg = p.pkg()
// read objects of phase 1 only (see cmd/compiler/internal/gc/bexport.go)
objcount := 0