}
// Every module path in mods is a prefix of the import path.
- // As in QueryPackage, prefer the longest prefix that satisfies the import.
+ // As in QueryPattern, prefer the longest prefix that satisfies the import.
sort.Slice(mods, func(i, j int) bool {
return len(mods[i].Path) > len(mods[j].Path)
})
// in the build list, and isn't in any other module that the user has
// shimmed in via a "replace" directive.
// Moreover, the import path is reserved for the standard library, so
- // QueryPackage cannot possibly find a module containing this package.
+ // QueryPattern cannot possibly find a module containing this package.
//
- // Instead of trying QueryPackage, report an ImportMissingError immediately.
+ // Instead of trying QueryPattern, report an ImportMissingError immediately.
return module.Version{}, &ImportMissingError{Path: path}
}
// and return m, dir, ImpportMissingError.
fmt.Fprintf(os.Stderr, "go: finding module for package %s\n", path)
- candidates, err := QueryPackage(ctx, path, "latest", CheckAllowed)
+ candidates, err := QueryPattern(ctx, path, "latest", CheckAllowed)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
// Return "cannot find module providing package […]" instead of whatever
- // low-level error QueryPackage produced.
+ // low-level error QueryPattern produced.
return module.Version{}, &ImportMissingError{Path: path, QueryErr: err}
} else {
return module.Version{}, err
canAdd := true
for _, bm := range buildList {
if bm.Path == cm.Path && semver.Compare(bm.Version, cm.Version) > 0 {
- // QueryPackage proposed that we add module cm to provide the package,
+ // QueryPattern proposed that we add module cm to provide the package,
// but we already depend on a newer version of that module (and we don't
// have the package).
//
return
}
+ if search.IsMetaPackage(pkg.path) {
+ pkg.err = &invalidImportError{
+ importPath: pkg.path,
+ err: fmt.Errorf("%q is not an importable package; see 'go help packages'", pkg.path),
+ }
+ return
+ }
+
pkg.mod, pkg.dir, pkg.err = importFromBuildList(context.TODO(), pkg.path)
if pkg.dir == "" {
return
Packages []string
}
-// QueryPackage looks up the module(s) containing path at a revision matching
-// query. The results are sorted by module path length in descending order.
-//
-// If the package is in the main module, QueryPackage considers only the main
-// module and only the version "latest", without checking for other possible
-// modules.
-func QueryPackage(ctx context.Context, path, query string, allowed AllowedFunc) ([]QueryResult, error) {
- m := search.NewMatch(path)
- if m.IsLocal() || !m.IsLiteral() {
- return nil, fmt.Errorf("pattern %s is not an importable package", path)
- }
- return QueryPattern(ctx, path, query, allowed)
-}
-
// QueryPattern looks up the module(s) containing at least one package matching
// the given pattern at the given version. The results are sorted by module path
// length in descending order.
# Initially, our module depends on split-incompatible v2.1.0-pre+incompatible,
# from which an imported package has been removed (and relocated to the nested
-# split-incompatible/subpkg module). modload.QueryPackage will suggest
+# split-incompatible/subpkg module). modload.QueryPattern will suggest
# split-incompatible v2.0.0+incompatible, which we cannot use (because it would
# be an implicit downgrade), and split-incompatible/subpkg v0.1.0, which we
# *should* use.
--- /dev/null
+# The loader should not attempt to resolve imports of the "all", "std", and "cmd" meta-packages.
+
+! go list -deps ./importall
+! stderr 'internal error'
+stderr '^importall[/\\]x.go:3:8: "all" is not an importable package; see ''go help packages''$'
+
+! go list -deps ./importcmd
+! stderr 'internal error'
+stderr '^importcmd[/\\]x.go:3:8: "cmd" is not an importable package; see ''go help packages''$'
+
+! go list -deps ./importstd
+! stderr 'internal error'
+stderr '^importstd[/\\]x.go:3:8: "std" is not an importable package; see ''go help packages''$'
+
+
+# Not even if such a path is theoretically provided by a (necessarily replaced) module.
+
+go mod edit -replace std@v0.1.0=./modstd
+go mod edit -require std@v0.1.0
+
+! go list -deps ./importstd
+stderr '^importstd[/\\]x.go:3:8: "std" is not an importable package; see ''go help packages''$'
+
+
+-- go.mod --
+module example.com
+go 1.16
+-- importall/x.go --
+package importall
+
+import _ "all"
+-- importcmd/x.go --
+package importcmd
+
+import _ "cmd"
+-- importstd/x.go --
+package importstd
+
+import _ "std"
+-- modstd/go.mod --
+module std
+go 1.16
+-- modstd/std.go --
+// Package std is an incredibly confusingly-named package.
+package std