go/importer: don't return packages that are not fully type-checked

Fixes #20837.

Change-Id: I266519c26c8849da267b77e11abe7734d8275112
Reviewed-on: https://go-review.googlesource.com/47074
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2017-06-28 15:04:47 -07:00
parent 9745e88b22
commit 773504aee5
1 changed files with 5 additions and 2 deletions

View File

@ -136,8 +136,11 @@ func (p *Importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*type
}
pkg, err = conf.Check(bp.ImportPath, p.fset, files, nil)
if err != nil {
// return (possibly nil or incomplete) package with error (see #16088)
return pkg, fmt.Errorf("type-checking package %q failed (%v)", bp.ImportPath, err)
// Type-checking stops after the first error (types.Config.Error is not set),
// so the returned package is very likely incomplete. Don't return it since
// we don't know its condition: It's very likely unsafe to use and it's also
// not added to p.packages which may cause further problems (issue #20837).
return nil, fmt.Errorf("type-checking package %q failed (%v)", bp.ImportPath, err)
}
p.packages[bp.ImportPath] = pkg