Bug report #11475

bad bracket simplification in expression

Added by Denis Rouzaud about 5 years ago. Updated over 4 years ago.

Status:Closed
Priority:Normal
Assignee:Jürgen Fischer
Category:Expressions
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

Description

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 about 5 years ago

expressions: keep brackets (fix #11475)

Revision a518e9f6
Added by Denis Rouzaud over 4 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 over 4 years ago

Expressions: preserve brackets for right-associative operators

Fixes #11475

History

#1 Updated by Jürgen Fischer about 5 years ago

  • Status changed from Open to Closed

#2 Updated by Martin Dobias about 5 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()
64.0
>>> e.dump()
u'2 ^ 3 ^ 2'
>>> QgsExpression(e.dump()).evaluate()
512.0

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

#4 Updated by Anonymous over 4 years ago

  • Status changed from Reopened to Closed

Also available in: Atom PDF