Skip to content

Commit 0c7311e

Browse files
committed
cmd/go: do not try to load 'all' packages with invalid import paths
Before this change, when we tried to compute the set of packages in 'all', we'd add packages with invalid import paths to the set and try to load them, which would fail. Instead, do not add them to the list of packages to load in the second iteration of the loader. We'll still return errors for invalid imports in the importing packages. Change-Id: I682229011f555ed1d0c827f79100c1c43bf7f93a Reviewed-on: https://go-review.googlesource.com/c/go/+/673655 Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 3e82316 commit 0c7311e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/cmd/go/internal/modload/load.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,13 @@ func (ld *loader) stdVendor(parentPath, path string) string {
20092009
// starting with a list of the import paths for the packages in the main module.
20102010
func (ld *loader) computePatternAll() (all []string) {
20112011
for _, pkg := range ld.pkgs {
2012+
if module.CheckImportPath(pkg.path) != nil {
2013+
// Don't add packages with invalid paths. This means that
2014+
// we don't try to load invalid imports of the main modules'
2015+
// packages. We will still report an errors invalid imports
2016+
// when we load the importing package.
2017+
continue
2018+
}
20122019
if pkg.flags.has(pkgInAll) && !pkg.isTest() {
20132020
all = append(all, pkg.path)
20142021
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
! go list all
2+
! stderr 'panic'
3+
stderr 'invalid import path'
4+
5+
# go list produces a package for 'p' but not for ''
6+
go list -e all
7+
cmp stdout wantlist.txt
8+
-- wantlist.txt --
9+
example.com/e
10+
-- go.mod --
11+
module example.com/e
12+
13+
go 1.25
14+
-- p.go --
15+
package p
16+
17+
import ""

0 commit comments

Comments
 (0)