-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/parser: poor error recovery after missing function call argument #58833
Comments
This specific error is perhaps not too hard to fix individually. Re-using the compiler's syntax package's parser code, but producing go/ast may be a good solution in the long run. Perhaps parts of it can be copied in pieces. E.g., the parts the parse parameter lists could be copied and adjusted to produce go/ast, and as a "side-effect" this bug might get fixed. |
Another version of the same recovery cascade:
FWIW, pretty printing the damaged tree produces only a small part of it:
|
For reference, for the above program, the compiler produces simply
|
Change https://go.dev/cl/493616 mentions this issue: |
Parser error recovery can delete large swathes of source code; see golang/go#58833 for examples. Type checking syntax trees containing syntax errors may therefore result in a large number of spurious type errors. So, this change suppressed type errors in the presence of syntax errors. Fiddling with these tests is really surprisingly time consuming. Fixes golang/go#59888 Change-Id: Ib489ecf46652c5a346d9caad89fd059434c620f8 Reviewed-on: https://go-review.googlesource.com/c/tools/+/493616 TryBot-Result: Gopher Robot <gobot@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Alan Donovan <adonovan@google.com>
Here's a variant distilled from #68918 in which the parser swallowed (originally) thousands of lines during recovery:
Using the types playground, this parse tree is pretty printed as:
Observe that recovery consumes the |
This program contains a syntax error in
Abs(,)
that causes the parser's recovery to generate a BadExpr formath.Lde
.This causes go/types not to recognize
math
as a reference to a package, and causes completions in gopls to misbehave.I think the parser could do a better job of recovery. @griesemer gives reasons why this is difficult in #24327 (comment):
Related issue of gopls completion after a syntax error:
The text was updated successfully, but these errors were encountered: