mirror of
https://github.com/golang/go
synced 2024-11-18 14:24:44 -07:00
x/tools/internal/imports: don't load package names for empty list
goimports should not attempt to load package names for an empty list of packages. 'go list' interprets an empty argument list as '.', which may or may not be a package. Fixes golang/go#33175 Change-Id: Id8df148432437295905c52f2d5fb73d890277569 Reviewed-on: https://go-review.googlesource.com/c/tools/+/188379 Run-TryBot: Jay Conrod <jayconrod@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
This commit is contained in:
parent
c001e47e7f
commit
5a5cfefe1f
@ -714,6 +714,9 @@ type goPackagesResolver struct {
|
||||
}
|
||||
|
||||
func (r *goPackagesResolver) loadPackageNames(importPaths []string, srcDir string) (map[string]string, error) {
|
||||
if len(importPaths) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
cfg := r.env.newPackagesConfig(packages.LoadFiles)
|
||||
pkgs, err := packages.Load(cfg, importPaths...)
|
||||
if err != nil {
|
||||
|
@ -1306,7 +1306,6 @@ var (
|
||||
"myotherpackage/toformat.go": input,
|
||||
},
|
||||
},
|
||||
goPackagesIncompatible: true, // https://golang.org/issue/33175
|
||||
}.processTest(t, "golang.org/fake", "myotherpackage/toformat.go", nil, nil, want)
|
||||
}
|
||||
|
||||
@ -1435,7 +1434,6 @@ var _ = race.Acquire
|
||||
"bar/x.go": input,
|
||||
},
|
||||
},
|
||||
goPackagesIncompatible: true, // https://golang.org/issue/33175
|
||||
}.processTest(t, "foo.com", "bar/x.go", nil, nil, importAdded)
|
||||
|
||||
// Packages outside the same directory should not.
|
||||
@ -1648,7 +1646,6 @@ const Y = bar.X
|
||||
"test/t.go": input,
|
||||
},
|
||||
},
|
||||
goPackagesIncompatible: true, // https://golang.org/issue/33175
|
||||
}.processTest(t, "foo.com", "test/t.go", nil, nil, want)
|
||||
}
|
||||
|
||||
@ -1836,7 +1833,6 @@ const Y = foo.X
|
||||
"x/x.go": input,
|
||||
},
|
||||
},
|
||||
goPackagesIncompatible: true, // https://golang.org/issue/33175
|
||||
}.processTest(t, "foo.com", "x/x.go", nil, nil, want)
|
||||
}
|
||||
|
||||
@ -2143,7 +2139,6 @@ var _ = pkg.DoIt
|
||||
"pkg/x_test.go": input,
|
||||
},
|
||||
},
|
||||
goPackagesIncompatible: true, // https://golang.org/issue/33175
|
||||
}.processTest(t, "foo.com", "pkg/x_test.go", nil, nil, want)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user