From 22c3443cadd8bc6b1faa619dceaadf5ea137fa65 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Wed, 11 Sep 2019 13:30:34 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- go/packages/packages.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/go/packages/packages.go b/go/packages/packages.go index 7450d21bc9..50b93c859b 100644 --- a/go/packages/packages.go +++ b/go/packages/packages.go @@ -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)