Repository navigation
Open
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Description
While investigating #70725, i noticed that, errors from the scanner are passed directly to p.errors:
Lines 69 to 71 in 8c3e391
| p.file = file | |
| eh := func(pos token.Position, msg string) { p.errors.Add(pos, msg) } | |
| p.scanner.Init(p.file, src, eh, scanner.ScanComments) |
Per the docs i would assume that the parsing should stop after 10 error (including scanner errors):
Line 57 in 8c3e391
| AllErrors = SpuriousErrors // report all errors (not just the first 10 on different lines) |
It should probably call the p.errors instead:
Lines 260 to 281 in 8c3e391
| func (p *parser) error(pos token.Pos, msg string) { | |
| if p.trace { | |
| defer un(trace(p, "error: "+msg)) | |
| } | |
| epos := p.file.Position(pos) | |
| // If AllErrors is not set, discard errors reported on the same line | |
| // as the last recorded error and stop parsing if there are more than | |
| // 10 errors. | |
| if p.mode&AllErrors == 0 { | |
| n := len(p.errors) | |
| if n > 0 && p.errors[n-1].Pos.Line == epos.Line { | |
| return // discard - likely a spurious error | |
| } | |
| if n > 10 { | |
| panic(bailout{}) | |
| } | |
| } | |
| p.errors.Add(epos, msg) | |
| } |
Metadata
Metadata
Assignees
Labels
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Activity
[-]go/parser: scanner errors do not cause a bailout, when AllErrors is not set[/-][+]go/parser: scanner errors do not cause a bailout[/+]gopherbot commentedon Dec 9, 2024
Change https://go.dev/cl/634538 mentions this issue:
go/parser: report scanner error by p.errorsgabyhelp commentedon Dec 9, 2024
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
griesemer commentedon Dec 11, 2024
Note that initializing the scanner with Scanner.Init may lead to an error because Init reads the first character. This would cause the parser's error handler to be called before the parser is fully set up (hence the current structure). The scanner initialization may have to happen just before calling Next.