[Bugfix] Expression: fix precedence+associativity management in parenthesis removal

Fixes #6948
This commit is contained in:
0penBrain
2022-06-01 12:31:43 +02:00
committed by wwmayer
parent b7d8d26c52
commit d96a7ac9d8
2 changed files with 5 additions and 4 deletions

View File

@@ -1517,7 +1517,7 @@ void OperatorExpression::_toString(std::ostream &s, bool persistent,int) const
leftOperator = static_cast<OperatorExpression*>(left)->op;
if (left->priority() < priority()) // Check on operator priority first
needsParens = true;
else if (leftOperator == op) { // Equal priority?
else if (leftOperator == op) { // Same operator ?
if (!isLeftAssociative())
needsParens = true;
//else if (!isCommutative())
@@ -1588,14 +1588,14 @@ void OperatorExpression::_toString(std::ostream &s, bool persistent,int) const
rightOperator = static_cast<OperatorExpression*>(right)->op;
if (right->priority() < priority()) // Check on operator priority first
needsParens = true;
else if (rightOperator == op) { // Equal priority?
else if (rightOperator == op) { // Same operator ?
if (!isRightAssociative())
needsParens = true;
else if (!isCommutative())
needsParens = true;
}
else if (right->priority() == priority()) {
if (!isRightAssociative())
else if (right->priority() == priority()) { // Same priority ?
if (!isRightAssociative() || rightOperator == MOD)
needsParens = true;
}

View File

@@ -1551,6 +1551,7 @@ class DocumentExpressionCases(unittest.TestCase):
# must not raise a topological error
self.assertEqual(self.Doc.recompute(), 2)
def testIssue4649(self):
class Cls():
def __init__(self, obj):