mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/syntax: don't panic if no error handler is provided
If no error handler is provided, terminate parsing with first error and report that error. Fixes #17697. Change-Id: I9070faf7239bd53725de141507912b92ded3474b Reviewed-on: https://go-review.googlesource.com/32456 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
53fc330e2d
commit
7a26d9fced
3 changed files with 29 additions and 6 deletions
|
|
@ -28,6 +28,8 @@ type parser struct {
|
|||
nerrors int // error count
|
||||
}
|
||||
|
||||
type parserError string // for error recovery if no error handler was installed
|
||||
|
||||
func (p *parser) init(src io.Reader, errh ErrorHandler, pragh PragmaHandler) {
|
||||
p.scanner.init(src, func(pos, line int, msg string) {
|
||||
p.nerrors++
|
||||
|
|
@ -35,7 +37,7 @@ func (p *parser) init(src io.Reader, errh ErrorHandler, pragh PragmaHandler) {
|
|||
errh(pos, line, msg)
|
||||
return
|
||||
}
|
||||
panic(fmt.Sprintf("%d: %s\n", line, msg))
|
||||
panic(parserError(fmt.Sprintf("%d: %s\n", line, msg)))
|
||||
}, pragh)
|
||||
|
||||
p.fnest = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue