Commit de050717 authored by Udalov Max's avatar Udalov Max Committed by Jay Conrod

cmd/go/internal/modcmd: assign module's path and version to fileJSON when...

cmd/go/internal/modcmd: assign module's path and version to fileJSON when modFile's module statement exists

Fixes panic on nil pointer dereference error when assigning module's path and version pair to fileJSON.

Fixes #31623

Change-Id: I3f61122ba0676a1270d3ad98900af8c8e9c90935
Reviewed-on: https://go-review.googlesource.com/c/go/+/173397
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarJay Conrod <jayconrod@google.com>
parent 601eee39
...@@ -385,7 +385,9 @@ type replaceJSON struct { ...@@ -385,7 +385,9 @@ type replaceJSON struct {
// editPrintJSON prints the -json output. // editPrintJSON prints the -json output.
func editPrintJSON(modFile *modfile.File) { func editPrintJSON(modFile *modfile.File) {
var f fileJSON var f fileJSON
f.Module = modFile.Module.Mod if modFile.Module != nil {
f.Module = modFile.Module.Mod
}
if modFile.Go != nil { if modFile.Go != nil {
f.Go = modFile.Go.Version f.Go = modFile.Go.Version
} }
......
...@@ -25,6 +25,10 @@ cmpenv go.mod $WORK/go.mod.edit2 ...@@ -25,6 +25,10 @@ cmpenv go.mod $WORK/go.mod.edit2
go mod edit -json go mod edit -json
cmpenv stdout $WORK/go.mod.json cmpenv stdout $WORK/go.mod.json
# go mod edit -json (empty mod file)
go mod edit -json $WORK/go.mod.empty
cmp stdout $WORK/go.mod.empty.json
# go mod edit -replace # go mod edit -replace
go mod edit -replace=x.1@v1.3.0=y.1/v2@v2.3.5 -replace=x.1@v1.4.0=y.1/v2@v2.3.5 go mod edit -replace=x.1@v1.3.0=y.1/v2@v2.3.5 -replace=x.1@v1.4.0=y.1/v2@v2.3.5
cmpenv go.mod $WORK/go.mod.edit3 cmpenv go.mod $WORK/go.mod.edit3
...@@ -168,4 +172,14 @@ require x.3 v1.99.0 ...@@ -168,4 +172,14 @@ require x.3 v1.99.0
-- $WORK/m/go.mod.edit -- -- $WORK/m/go.mod.edit --
module x.x/y/z module x.x/y/z
go $goversion go $goversion
\ No newline at end of file -- $WORK/go.mod.empty --
-- $WORK/go.mod.empty.json --
{
"Module": {
"Path": ""
},
"Require": null,
"Exclude": null,
"Replace": null
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment