type ImportMissingError struct {
ImportPath string
Module module.Version
+
+ // newMissingVersion is set to a newer version of Module if one is present
+ // in the build list. When set, we can't automatically upgrade.
+ newMissingVersion string
}
func (e *ImportMissingError) Error() string {
}
return module.Version{}, "", &ImportMissingError{ImportPath: path}
}
- return m, "", &ImportMissingError{ImportPath: path, Module: m}
+ newMissingVersion := ""
+ for _, bm := range buildList {
+ if bm.Path == m.Path && semver.Compare(bm.Version, m.Version) > 0 {
+ // This typically happens when a package is present at the "@latest"
+ // version (e.g., v1.0.0) of a module, but we have a newer version
+ // of the same module in the build list (e.g., v1.0.1-beta), and
+ // the package is not present there.
+ newMissingVersion = bm.Version
+ break
+ }
+ }
+ return m, "", &ImportMissingError{ImportPath: path, Module: m, newMissingVersion: newMissingVersion}
}
// maybeInModule reports whether, syntactically,
}
for _, pkg := range ld.pkgs {
if err, ok := pkg.err.(*ImportMissingError); ok && err.Module.Path != "" {
+ if err.newMissingVersion != "" {
+ base.Fatalf("go: %s: package provided by %s at latest version %s but not at required version %s", pkg.stackText(), err.Module.Path, err.Module.Version, err.newMissingVersion)
+ }
if added[pkg.path] {
base.Fatalf("go: %s: looping trying to add package", pkg.stackText())
}
--- /dev/null
+The deprecated package is present in this version (which is @latest) but
+is deleted in a newer prerelease version.
+
+-- .mod --
+module example.com/missingpkg
+-- .info --
+{"Version":"v1.0.0"}
+-- lib.go --
+package lib
+-- deprecated/deprecated.go --
+package deprecated
--- /dev/null
+This module requires example.com/missingpkg at a prerelease version, which
+is newer than @latest.
+
+-- .mod --
+module example.com/usemissingpre
+
+require example.com/missingpkg v1.0.1-beta
+-- .info --
+{"Version":"v1.0.0"}
+-- use.go --
+package use
+
+import _ "example.com/missingpkg"