aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/load/pkg.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2021-04-27 03:01:08 -0400
committerBryan C. Mills <bcmills@google.com>2021-04-27 18:34:55 +0000
commit8e0023b81b81352c1f8ea5cd58eea91939924f9d (patch)
tree8dee53704eb0dc0a3fc5999823651ab27e893d11 /src/cmd/go/internal/load/pkg.go
parentbd2175e1b1369bce59cdceb9282c817802a87746 (diff)
downloadgo-8e0023b81b81352c1f8ea5cd58eea91939924f9d.tar.gz
go-8e0023b81b81352c1f8ea5cd58eea91939924f9d.zip
cmd/go/internal/load: treat packages with errors as potentially main packages
If a package declares 'package main' but for some reason we fail to read its name (for example, due to a permission or checksum error), we may be tempted to drop the package from the output of mainPackagesOnly. However, that leads to a confusing "no packages loaded from …" error message. Instead, we will treat packages with errors as potentially-main packages, and print the error. At least if we print why the package is broken, the user will understand that the weird behavior is due to the broken package rather than, say, a typo on their part in the command arguments. Updates #42088 For #36460 Change-Id: I033c0d28ac7d105d9df3ba5f9327e5c0c2a29954 Reviewed-on: https://go-review.googlesource.com/c/go/+/314050 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/load/pkg.go')
-rw-r--r--src/cmd/go/internal/load/pkg.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go
index acba232308..c1e3eaa0f3 100644
--- a/src/cmd/go/internal/load/pkg.go
+++ b/src/cmd/go/internal/load/pkg.go
@@ -2563,7 +2563,7 @@ func mainPackagesOnly(pkgs []*Package, patterns []string) []*Package {
mainCount := make([]int, len(patterns))
nonMainCount := make([]int, len(patterns))
for _, pkg := range pkgs {
- if pkg.Name == "main" {
+ if pkg.Name == "main" || (pkg.Incomplete && pkg.Name == "") {
matchedPkgs = append(matchedPkgs, pkg)
for i := range patterns {
if matchers[i] != nil && matchers[i](pkg.ImportPath) {