Skip to content

Commit b7f4307

Browse files
committed
cmd/compile: graceful handle error in noder LoadPackage
When syntax.Parse returns error, noder.file will be nil. Currently, we continue accessing it regardlessly and depend on gc.hidePanic to hide the panic from user. Instead, we should gracefully handle the error in LoadPackage, then exit earlier if any error occurred. Updates #43311 Change-Id: I0a108ef360bd4f0cc9f481071b8967355e1513af Reviewed-on: https://go-review.googlesource.com/c/go/+/294030 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 4532467 commit b7f4307

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/cmd/compile/internal/noder/noder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ func LoadPackage(filenames []string) {
6868
for e := range p.err {
6969
p.errorAt(e.Pos, "%s", e.Msg)
7070
}
71+
if p.file == nil {
72+
base.ErrorExit()
73+
}
7174
lines += p.file.EOF.Line()
7275
}
7376
base.Timer.AddEvent(int64(lines), "lines")

test/fixedbugs/bug050.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// errorcheck
1+
// errorcheck -d=panic
22

33
// Copyright 2009 The Go Authors. All rights reserved.
44
// Use of this source code is governed by a BSD-style

0 commit comments

Comments
 (0)