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

Fix precedence of negation vs comparison #69

Closed
wants to merge 1 commit into from
Closed

Fix precedence of negation vs comparison #69

wants to merge 1 commit into from

Conversation

mntnorv
Copy link
Contributor

@mntnorv mntnorv commented Apr 29, 2022

Fixed antlr grammar to correctly prioritize negation vs comparison when parsing.

Before fix, expression !foo == 'bar' was parsed into:

Negate(Comparison(==, Property(Foo), String(bar)))

After fix, expression !foo == 'bar' is parsed into:

Comparison(==, Negate(Property(Foo)), String(bar))

Taking the JS implementation as the source of truth, because it prioritizes negation vs comparison. Example:

search(!foo == `true`, {"foo":1}) // false

First foo (which is equal to 1) is negated, resulting in false. Then, the result is compared to true, so the final result is false. Before the fix, this Java implementation would return true for the same expression, because first foo is compared to true, which results in false (because 1 != true) and the result is negated, resulting in true.

This pull request was closed.
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.

1 participant