When concatenating multiple main modules' roots we need to resort
the list of main module roots. This avoids a panic from unsorted main
module roots. This will get better when we have structured module
roots.
Change-Id: I68fed47b0f3b131ed3dadf45db3c442286a0ced0
Reviewed-on: https://go-review.googlesource.com/c/go/+/338111
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
}
roots = append(roots, min...)
}
+ if MainModules.Len() > 1 {
+ module.Sort(roots)
+ }
if rs.depth == eager && reflect.DeepEqual(roots, rs.rootModules) && reflect.DeepEqual(direct, rs.direct) {
// The root set is unchanged and rs was already eager, so keep rs to
// preserve its cached ModuleGraph (if any).
cp go.work.d go.work
go run example.com/d
+# Test that we don't run into "newRequirements called with unsorted roots"
+# panic with unsorted main modules.
+cp go.work.backwards go.work
+go run example.com/d
+
-- go.work.dup --
go 1.17
func main() {
lib.Hello()
}
+
+-- go.work.backwards --
+go 1.18
+
+directory (
+ d
+ b
+ a
+)
\ No newline at end of file