From: Fabien Potencier Date: Fri, 6 Jan 2012 18:47:50 +0000 (+0100) Subject: fixed unary operators precedence (closes #583) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=8fb4172a046d2f553769283403fe519cbdde83e7;p=web%2Fkonrad%2Ftwig.git fixed unary operators precedence (closes #583) --- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index f5d2acd..a0dbfc9 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -189,8 +189,8 @@ class Twig_Extension_Core extends Twig_Extension return array( array( 'not' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), - '-' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Neg'), - '+' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Pos'), + '-' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Neg'), + '+' => array('precedence' => 500, 'class' => 'Twig_Node_Expression_Unary_Pos'), ), array( 'b-and' => array('precedence' => 5, 'class' => 'Twig_Node_Expression_Binary_BitwiseAnd', 'associativity' => Twig_ExpressionParser::OPERATOR_LEFT), diff --git a/test/Twig/Tests/Fixtures/expressions/unary_precedence.test b/test/Twig/Tests/Fixtures/expressions/unary_precedence.test new file mode 100644 index 0000000..cc6eef8 --- /dev/null +++ b/test/Twig/Tests/Fixtures/expressions/unary_precedence.test @@ -0,0 +1,14 @@ +--TEST-- +Twig unary operators precedence +--TEMPLATE-- +{{ -1 - 1 }} +{{ -1 - -1 }} +{{ -1 * -1 }} +{{ 4 / -1 * 5 }} +--DATA-- +return array() +--EXPECT-- +-2 +0 +1 +-20