Skip to content

Commit 22c3443

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 44811c0 commit 22c3443

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

go/packages/packages.go

+8
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,14 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
770770
lpkg.Errors = append(lpkg.Errors, errs...)
771771
}
772772

773+
if len(lpkg.CompiledGoFiles) == 0 && lpkg.ExportFile != "" {
774+
// The config requested loading sources and types, but sources are missing.
775+
// Add an error to the package and fall back to loading from export data.
776+
appendError(Error{"-", fmt.Sprintf("sources missing for package %s", lpkg.ID), ParseError})
777+
ld.loadFromExportData(lpkg)
778+
return // can't get syntax trees for this package
779+
}
780+
773781
files, errs := ld.parseFiles(lpkg.CompiledGoFiles)
774782
for _, err := range errs {
775783
appendError(err)

0 commit comments

Comments
 (0)