Skip to content
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

Ensure an error is emitted when parsing a stmt after a last stmt in the top level block #302

Merged
merged 4 commits into from
Jul 6, 2024

Conversation

JohnnyMorganz
Copy link
Collaborator

There is code that "merges" two top level blocks when performing initial parsing. This code does not account for the fact that a stmt parsed after a last stmt is invalid syntax. We extend it to ensure an error is reported in this case.

Note that we do not resolve the problem where the stmts after the last stmt "teleport" in front of the last stmt in the AST. That is more difficult to sort without restructuring the AST. However this was originally parsed as invalid syntax so we now at least emit an error and do not guarantee the state of an invalid syntax tree.

Partially resolves #298

Ensure an error is emitted if there is a statement after a last statement
@@ -315,6 +317,14 @@ impl AstResult {
continue;
}

if block_has_last_stmt {
use crate::node::Node;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just put this in the beginning

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was lazy because it clashes with start_position / end_position on TokenReference. If we stick it at the top we need to disambiguate all other usages

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in last commit, wasn't that bad. Can revert if we want to

@Kampfkarren Kampfkarren merged commit 74c20d5 into main Jul 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 last statements in single top level block doesn't error recover well
2 participants