diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 103076576b..a682d9422a 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -1517,7 +1517,7 @@ void OperatorExpression::_toString(std::ostream &s, bool persistent,int) const leftOperator = static_cast(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(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; } diff --git a/src/Mod/Test/Document.py b/src/Mod/Test/Document.py index 3cf2eadf28..3fc39730ab 100644 --- a/src/Mod/Test/Document.py +++ b/src/Mod/Test/Document.py @@ -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):