-
Notifications
You must be signed in to change notification settings - Fork 18k
go/ast: establish File.FileStart <= Node.Pos <= Node.End <= File.FileEnd for all Nodes in a File #73438
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
Comments
Thank you for filing this issue. It should be a proposal, since it will require adding new fields to the AST. However, I consider it a bug that End overflows the file. It should be the case that if the parser accepts a The alternative would be to use BadExpr for a dangling My preference would be to:
Note that |
I agree it will need a proposal, but the first step is to investigate what changes are needed to the parser and go/ast. Once that's done, we can turn this into a proposal. A complete audit is required; StructType is just one of the known problematic cases. It's possible that StructType can be fixed with only a change to the logic in End. For example:
|
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
@jba, I am stealing this from you. |
Change https://go.dev/cl/668238 mentions this issue: |
Change https://go.dev/cl/668677 mentions this issue: |
Background: Some ast.Node types, such as ast.StructType and ast.InterfaceType, compute their End position based on assumptions about where "}" braces appear in well-formed input. However, in a truncated file--a common input to gopls when one is composing a new file--the brace may be missing and the computed End position may be beyond EOF; or it may be zero. Both have been a widespread source of bugs (e.g. 71659).
Proposal: We propose to establish
(a) the invariant that, in all ast.File trees produced by the parser, every Node has a non-zero Pos and End value, and
(b) the inequality File.FileStart <= Node.Pos <= Node.End <= and File.End.
This will likely require the addition of new fields to record token.Pos values (or their absence) in the AST.
@jba @findleyr @griesemer
The text was updated successfully, but these errors were encountered: