Commit 07bcfe57 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarBryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b800f202
......@@ -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
......
# 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
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