Bug report #11475

bad bracket simplification in expression

Added by Denis Rouzaud over 9 years ago. Updated almost 9 years ago.

Assignee:Jürgen Fischer
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:19745


I noticed that this expression
1 - ( 2 -1 )
is simplified to
1 -2 - 1
leading to wrong result.

Associated revisions

Revision 2c7378bb
Added by Jürgen Fischer over 9 years ago

expressions: keep brackets (fix #11475)

Revision a518e9f6
Added by Denis Rouzaud almost 9 years ago

[fix #11475] expressions: add left and right associavity for dump of binary operators

complete test for left associativity

Revision 8342739b
Added by Matthias Kuhn almost 9 years ago

Expressions: preserve brackets for right-associative operators

Fixes #11475


#1 Updated by Jürgen Fischer over 9 years ago

  • Status changed from Open to Closed

#2 Updated by Martin Dobias over 9 years ago

  • Affected QGIS version changed from 2.4.0 to master
  • Priority changed from Severe/Regression to Normal
  • Status changed from Closed to Reopened

The code assumes that the binary operators are left associative - which is true except for the power operator:

>>> e=QgsExpression("(2^3)^2")
>>> e.evaluate()
>>> e.dump()
u'2 ^ 3 ^ 2'
>>> QgsExpression(e.dump()).evaluate()

Given the fact that expressions like A^B^C are rare I'm lowering the priority.

#4 Updated by Anonymous almost 9 years ago

  • Status changed from Reopened to Closed

Also available in: Atom PDF