Twig icon indicating copy to clipboard operation
Twig copied to clipboard

Wrong precedence of NOT operator

Open mhcwebdesign opened this issue 3 years ago • 1 comments

In most programming languages (such as C++, Java, or PHP) the boolean unary NOT operator has a higher precedence than e.g. the multiplication, division, remainder, or relational operators. It usually has a precedence same as the unary '+' or unary '-'.

But why does Twig deviate from this practice and puts the unary 'NOT' operator precedence between the ones below:

.... '+' (binary add) '-' (binary minus) '~' (binary concat) 'NOT' (unary not) '*' (binary multiply) '/' (binary division) ....

Not even Django (Python) has such a strange precedence placement.

There are several other bad habits in the Twig expression syntax, but I think above mentioned issue could be fixed, and if need be, add a runtime switch to ensure backward compatibility with older Twig versions, but have future Twig releases use a proper operator precedence.

mhcwebdesign avatar Feb 06 '22 16:02 mhcwebdesign

This is a good point, however I don't think it will ever be changed, it would be too sensitive for users to move. This can have serious consequences on calculations etc.

lacatoire avatar Feb 29 '24 18:02 lacatoire