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

NodeToStringBuilder brackets bug for complex non-commutative operation expressions #3144

Open
fedakdenis opened this issue Dec 6, 2024 · 2 comments
Assignees
Labels

Comments

@fedakdenis
Copy link

Priority brackets bug for complex binary operations in

if (node.Right.Kind == QueryNodeKind.BinaryOperator && TranslateBinaryOperatorPriority(((BinaryOperatorNode)node.Right).OperatorKind) < TranslateBinaryOperatorPriority(node.OperatorKind) ||

For right node we have not to use < (less) to compare operator priority, but <= (less or equals).

Reproduce steps

I do not know how to reproduce it. The bug is in the internal class. So I do not understand how to implement test case for the fix?

Expected result

Correct brackets for complex non-commutative operator expressions expression with same priority a-(b-c), a/(b/c)

Actual result

In this case expression node a-(b-c) will be translated to a sub b sub c, but not to a sub (b sub c)

Additional detail

Would be cool if implement IsCommutative method for binary operators and use it to avoid redundant brackets for expressions like a+(b+c) or a*(b*c)

@corranrogue9
Copy link
Contributor

This might be in the actual parsing or it may be in the string builder, it's unclear. Let's set up a repro and investigate.

@WanjohiSammy
Copy link
Contributor

I have created a small repo to repro this issue:
https://github.com/WanjohiSammy/NodeToStringBuilderBracketsBugRepro

Still investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants