Skip to content

Commit e44fa1c

Browse files
samthanawallagopherbot
authored andcommitted
cmd/go: fix go list -u -m all with too new retractions dependency
Previously, go would not report retractions of dependencies that have a newer version of Go. With this change, we will still display retractions despite a version difference when go list -u -m is used. Fixes: #66403 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: I6406680235e294269836ae4cbe3d5680ca10eea0 Reviewed-on: https://go-review.googlesource.com/c/go/+/588775 Auto-Submit: Sam Thanawalla <[email protected]> Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent b691da9 commit e44fa1c

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-8
lines changed

src/cmd/go/internal/modload/modfile.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func CheckRetractions(ctx context.Context, m module.Version) (err error) {
190190
return err
191191
}
192192
summary, err := rawGoModSummary(rm)
193-
if err != nil {
193+
if err != nil && !errors.Is(err, gover.ErrTooNew) {
194194
return err
195195
}
196196

@@ -298,7 +298,7 @@ func CheckDeprecation(ctx context.Context, m module.Version) (deprecation string
298298
return "", err
299299
}
300300
summary, err := rawGoModSummary(latest)
301-
if err != nil {
301+
if err != nil && !errors.Is(err, gover.ErrTooNew) {
302302
return "", err
303303
}
304304
return summary.deprecated, nil
@@ -644,6 +644,8 @@ func goModSummary(m module.Version) (*modFileSummary, error) {
644644
// its dependencies.
645645
//
646646
// rawGoModSummary cannot be used on the main module outside of workspace mode.
647+
// The modFileSummary can still be used for retractions and deprecations
648+
// even if a TooNewError is returned.
647649
func rawGoModSummary(m module.Version) (*modFileSummary, error) {
648650
if gover.IsToolchain(m.Path) {
649651
if m.Path == "go" && gover.Compare(m.Version, gover.GoStrictVersion) >= 0 {
@@ -698,12 +700,7 @@ func rawGoModSummary(m module.Version) (*modFileSummary, error) {
698700
summary.require = append(summary.require, req.Mod)
699701
}
700702
}
701-
if summary.goVersion != "" && gover.Compare(summary.goVersion, gover.GoStrictVersion) >= 0 {
702-
if gover.Compare(summary.goVersion, gover.Local()) > 0 {
703-
return nil, &gover.TooNewError{What: "module " + m.String(), GoVersion: summary.goVersion}
704-
}
705-
summary.require = append(summary.require, module.Version{Path: "go", Version: summary.goVersion})
706-
}
703+
707704
if len(f.Retract) > 0 {
708705
summary.retract = make([]retraction, 0, len(f.Retract))
709706
for _, ret := range f.Retract {
@@ -714,6 +711,16 @@ func rawGoModSummary(m module.Version) (*modFileSummary, error) {
714711
}
715712
}
716713

714+
// This block must be kept at the end of the function because the summary may
715+
// be used for reading retractions or deprecations even if a TooNewError is
716+
// returned.
717+
if summary.goVersion != "" && gover.Compare(summary.goVersion, gover.GoStrictVersion) >= 0 {
718+
summary.require = append(summary.require, module.Version{Path: "go", Version: summary.goVersion})
719+
if gover.Compare(summary.goVersion, gover.Local()) > 0 {
720+
return summary, &gover.TooNewError{What: "module " + m.String(), GoVersion: summary.goVersion}
721+
}
722+
}
723+
717724
return summary, nil
718725
})
719726
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- .mod --
2+
module example.com/retract/newergoversion
3+
4+
go 1.21
5+
6+
-- .info --
7+
{"Version":"v1.0.0"}
8+
9+
-- retract.go --
10+
package newergoversion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- .mod --
2+
module example.com/retract/newergoversion
3+
4+
go 1.23
5+
6+
retract v1.2.0
7+
8+
-- .info --
9+
{"Version":"v1.2.0"}
10+
11+
-- retract.go --
12+
package newergoversion
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# For issue #66403, go list -u -m all should not fail if a module
2+
# with retractions has a newer version.
3+
4+
env TESTGO_VERSION=go1.21
5+
env TESTGO_VERSION_SWITCH=switch
6+
go list -u -m example.com/retract/newergoversion
7+
stdout 'example.com/retract/newergoversion v1.0.0'
8+
! stdout 'v1.2.0'
9+
10+
-- go.mod --
11+
module example.com/m
12+
13+
go 1.22
14+
15+
require example.com/retract/newergoversion v1.0.0
16+
17+
-- main.go --
18+
package main
19+
20+
import _ "example.com/retract/newergoversion"

0 commit comments

Comments
 (0)