Skip to content

Commit 6da1601

Browse files
seankhliaomatloob
authored andcommitted
cmd/go: check go version when parsing go.mod fails
Fixes #70979 Change-Id: I6597fe178eed34702eea6cba4eec5174c9203458 Reviewed-on: https://go-review.googlesource.com/c/go/+/639115 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent de9fdc7 commit 6da1601

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ func ReadModFile(gomod string, fix modfile.VersionFixer) (data []byte, f *modfil
4444

4545
f, err = modfile.Parse(gomod, data, fix)
4646
if err != nil {
47+
f, laxErr := modfile.ParseLax(gomod, data, fix)
48+
if laxErr == nil {
49+
if f.Go != nil && gover.Compare(f.Go.Version, gover.Local()) > 0 {
50+
toolchain := ""
51+
if f.Toolchain != nil {
52+
toolchain = f.Toolchain.Name
53+
}
54+
return nil, nil, &gover.TooNewError{What: base.ShortPath(gomod), GoVersion: f.Go.Version, Toolchain: toolchain}
55+
}
56+
}
57+
4758
// Errors returned by modfile.Parse begin with file:line.
4859
return nil, nil, fmt.Errorf("errors parsing %s:\n%w", base.ShortPath(gomod), shortPathErrorList(err))
4960
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
env GOTOOLCHAIN=local
2+
! go list .
3+
stderr 'go: go.mod requires go >= 1.999'
4+
5+
6+
-- go.mod --
7+
module example.com
8+
9+
go 1.999
10+
11+
anewblock foo

0 commit comments

Comments
 (0)