Restrict the lhs of assignments to fix a grammar conflict #2265
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem is very simple, when seeing:
in a statement context, the parser does not know with bounded lookahead whether it will see a mere function call, or an assignment of the form:
The latter is obviously not allowed by the language, but currently this restriction is only enforced at the type level instead of the syntax level. I propose adding these restrictions to the syntax to spare the parser from pointless backtracking:
Instead of the current approach where practically any expression can be on the left-hand side of an assignment.
I looked at all type rules that allow the creation of memory references (required for the left-hand side of an assignment), and I believe that I have captured all possible such expressions. I tried to verify it by checking that all of our examples still parse with the new grammar.
This allows removing one of the 3 known conflicts in the grammar today which prevent it from being LR(1). I hope to fix the other two in separate PRs.