test for assignment + logical operators precedence #189
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.
This PR adds (failing) test cases demonstrating an assignment operator vs logical operator precedence issue / behavior.
The issue
Compile errors first:
(
foo
should be assigned the value of'bar'
.)(
foo
should be assigned the value oftrue
.)Similar errors tested for
and
,||
andor
.All compile fine in the original coffeescript compiler.
For compleness, this works fine:
Existing workaround
Adding parens to group the assignment
foo = 'bar'
fixes all cases:Syntax discussion
I believe that this is an operator precedence issue. While logical operators should, of course, normally take precedence over assignment operators, this should only happen when the logical operator appears at the right hand side of the assignment operator.
Given
While the
&&
operator taking precedence over the assignment operator makes sense, the case of the||
operator would produce this semantically invalid parsing:Since all logical operators will produce a boolean primitive, and that boolean primitives cannot be the receiver of the assignment operator, an exception should be made to change the operator precedence on such cases, producing:
I'm sorry but I am not familiar with pegjs, so I can only produce a test case in this PR accompanied by this description.