aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/import.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-08-28 21:32:05 -0400
committerBryan C. Mills <bcmills@google.com>2020-09-09 21:29:10 +0000
commitcd91ab5d9601c975286f1ac83cd289e34aa117f8 (patch)
tree42509239c4f67bd12d56fc72bf75b3d6611a0838 /src/cmd/go/internal/modload/import.go
parent2c8d2a0c51f4085e56b5ab05ed9fb17fc6d08261 (diff)
downloadgo-cd91ab5d9601c975286f1ac83cd289e34aa117f8.tar.gz
go-cd91ab5d9601c975286f1ac83cd289e34aa117f8.zip
cmd/go/internal/modload: fix spurious import resolution error
Due to a bug in CL 173017, if QueryPackages found multiple candidates for the given package and *at least* one of those candidates was not available to add, we would reject *all* such candidates — even those that were still viable. Now, we return the first viable candidate, and only return an error if *no* candidate is viable given the current build list. Fixes #41113 Change-Id: Idb2e77244be7c0f5dd511efb142c3059925d7336 Reviewed-on: https://go-review.googlesource.com/c/go/+/251446 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/import.go')
-rw-r--r--src/cmd/go/internal/modload/import.go26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go
index e04d66c5b1..c625184b8b 100644
--- a/src/cmd/go/internal/modload/import.go
+++ b/src/cmd/go/internal/modload/import.go
@@ -312,10 +312,10 @@ func queryImport(ctx context.Context, path string) (module.Version, error) {
}
}
- m := candidates[0].Mod
- newMissingVersion := ""
- for _, c := range candidates {
+ candidate0MissingVersion := ""
+ for i, c := range candidates {
cm := c.Mod
+ 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,
@@ -326,20 +326,22 @@ func queryImport(ctx context.Context, path string) (module.Version, error) {
// 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.
- //
- // TODO(#41113): This is probably incorrect when there are multiple
- // candidates, such as when a nested module is split out but only one
- // half of the split is tagged.
- m = cm
- newMissingVersion = bm.Version
+ canAdd = false
+ if i == 0 {
+ candidate0MissingVersion = bm.Version
+ }
break
}
}
+ if canAdd {
+ return cm, nil
+ }
}
- if newMissingVersion != "" {
- return m, &ImportMissingError{Path: path, Module: m, newMissingVersion: newMissingVersion}
+ return module.Version{}, &ImportMissingError{
+ Path: path,
+ Module: candidates[0].Mod,
+ newMissingVersion: candidate0MissingVersion,
}
- return m, nil
}
// maybeInModule reports whether, syntactically,