1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:04:44 -07:00

go/packages: fall back to loading from export data if sources are missing

When a user asks Syntax or TypesInfo, we need to typecheck from sources.
If the sources are missing fall back to trying to load from export data,
but still report an error.
This will help in some cases where the driver has incomplete data.

Change-Id: I3b23e90a5cd865c5f729e50f09f5fadff2d32994
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194683
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Michael Matloob 2019-09-11 13:30:34 -04:00
parent 44811c0174
commit 22c3443cad

View File

@ -770,6 +770,14 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
lpkg.Errors = append(lpkg.Errors, errs...)
}
if len(lpkg.CompiledGoFiles) == 0 && lpkg.ExportFile != "" {
// The config requested loading sources and types, but sources are missing.
// Add an error to the package and fall back to loading from export data.
appendError(Error{"-", fmt.Sprintf("sources missing for package %s", lpkg.ID), ParseError})
ld.loadFromExportData(lpkg)
return // can't get syntax trees for this package
}
files, errs := ld.parseFiles(lpkg.CompiledGoFiles)
for _, err := range errs {
appendError(err)