Skip to content

Commit e65014d

Browse files
samthanawallajoedian
authored andcommitted
[release-branch.go1.21] 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. For: #66403 Fixes: #68051 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]> (cherry picked from commit e44fa1c) Reviewed-on: https://go-review.googlesource.com/c/go/+/593375
1 parent 74ac37e commit e65014d

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
@@ -637,6 +637,8 @@ func goModSummary(m module.Version) (*modFileSummary, error) {
637637
// its dependencies.
638638
//
639639
// rawGoModSummary cannot be used on the main module outside of workspace mode.
640+
// The modFileSummary can still be used for retractions and deprecations
641+
// even if a TooNewError is returned.
640642
func rawGoModSummary(m module.Version) (*modFileSummary, error) {
641643
if gover.IsToolchain(m.Path) {
642644
if m.Path == "go" && gover.Compare(m.Version, gover.GoStrictVersion) >= 0 {
@@ -691,12 +693,7 @@ func rawGoModSummary(m module.Version) (*modFileSummary, error) {
691693
summary.require = append(summary.require, req.Mod)
692694
}
693695
}
694-
if summary.goVersion != "" && gover.Compare(summary.goVersion, gover.GoStrictVersion) >= 0 {
695-
if gover.Compare(summary.goVersion, gover.Local()) > 0 {
696-
return nil, &gover.TooNewError{What: "module " + m.String(), GoVersion: summary.goVersion}
697-
}
698-
summary.require = append(summary.require, module.Version{Path: "go", Version: summary.goVersion})
699-
}
696+
700697
if len(f.Retract) > 0 {
701698
summary.retract = make([]retraction, 0, len(f.Retract))
702699
for _, ret := range f.Retract {
@@ -707,6 +704,16 @@ func rawGoModSummary(m module.Version) (*modFileSummary, error) {
707704
}
708705
}
709706

707+
// This block must be kept at the end of the function because the summary may
708+
// be used for reading retractions or deprecations even if a TooNewError is
709+
// returned.
710+
if summary.goVersion != "" && gover.Compare(summary.goVersion, gover.GoStrictVersion) >= 0 {
711+
summary.require = append(summary.require, module.Version{Path: "go", Version: summary.goVersion})
712+
if gover.Compare(summary.goVersion, gover.Local()) > 0 {
713+
return summary, &gover.TooNewError{What: "module " + m.String(), GoVersion: summary.goVersion}
714+
}
715+
}
716+
710717
return summary, nil
711718
})
712719
}
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)