From: Cuong Manh Le Date: Fri, 19 Feb 2021 05:42:57 +0000 (+0700) Subject: cmd/compile: graceful handle error in noder LoadPackage X-Git-Tag: go1.17beta1~1296 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b7f4307761;p=gostls13.git 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 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go index d692bf97aa..8c456e4561 100644 --- a/src/cmd/compile/internal/noder/noder.go +++ b/src/cmd/compile/internal/noder/noder.go @@ -68,6 +68,9 @@ func LoadPackage(filenames []string) { for e := range p.err { p.errorAt(e.Pos, "%s", e.Msg) } + if p.file == nil { + base.ErrorExit() + } lines += p.file.EOF.Line() } base.Timer.AddEvent(int64(lines), "lines") diff --git a/test/fixedbugs/bug050.go b/test/fixedbugs/bug050.go index aba68b1dcb..1e299ed99a 100644 --- a/test/fixedbugs/bug050.go +++ b/test/fixedbugs/bug050.go @@ -1,4 +1,4 @@ -// errorcheck +// errorcheck -d=panic // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style