mirror of
https://github.com/golang/go
synced 2024-09-06 00:19:45 +00:00
cmd/go: don't crash in go fmt on invalid input when using modules
Fixes #26792 Change-Id: I9a878180af28e3939b654fd88bed150010dffde0 Reviewed-on: https://go-review.googlesource.com/127856 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
b800f202dc
commit
07bcfe5745
|
@ -60,7 +60,7 @@ func runFmt(cmd *base.Command, args []string) {
|
|||
}()
|
||||
}
|
||||
for _, pkg := range load.PackagesAndErrors(args) {
|
||||
if modload.Enabled() && !pkg.Module.Main {
|
||||
if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
|
||||
if !printed {
|
||||
fmt.Fprintf(os.Stderr, "go: not formatting packages in dependency modules\n")
|
||||
printed = true
|
||||
|
|
13
src/cmd/go/testdata/script/mod_gofmt_invalid.txt
vendored
Normal file
13
src/cmd/go/testdata/script/mod_gofmt_invalid.txt
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Test for a crash in go fmt on invalid input when using modules.
|
||||
# Issue 26792.
|
||||
|
||||
env GO111MODULE=on
|
||||
! go fmt x.go
|
||||
! stderr panic
|
||||
|
||||
-- go.mod --
|
||||
module x
|
||||
|
||||
-- x.go --
|
||||
// Missing package declaration.
|
||||
var V int
|
Loading…
Reference in a new issue