diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index c1da0af88..83ef85730 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -302,11 +302,12 @@ final class CoreExtension extends AbstractExtension { return [ [ - 'not' => ['precedence' => 50, 'precedence_change' => new OperatorPrecedenceChange('twig/twig', '3.15', 70), 'class' => NotUnary::class], + 'not' => ['precedence' => 70, 'class' => NotUnary::class], '-' => ['precedence' => 500, 'class' => NegUnary::class], '+' => ['precedence' => 500, 'class' => PosUnary::class], ], [ + '??' => ['precedence' => 5, 'class' => NullCoalesceExpression::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT], 'or' => ['precedence' => 10, 'class' => OrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], 'xor' => ['precedence' => 12, 'class' => XorBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], 'and' => ['precedence' => 15, 'class' => AndBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT], @@ -338,7 +339,6 @@ final class CoreExtension extends AbstractExtension 'is' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], 'is not' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], '**' => ['precedence' => 200, 'class' => PowerBinary::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT], - '??' => ['precedence' => 300, 'precedence_change' => new OperatorPrecedenceChange('twig/twig', '3.15', 5), 'class' => NullCoalesceExpression::class, 'associativity' => ExpressionParser::OPERATOR_RIGHT], ], ]; } diff --git a/tests/Fixtures/operators/not_precedence.legacy.test b/tests/Fixtures/operators/not_precedence.legacy.test deleted file mode 100644 index 5178288e9..000000000 --- a/tests/Fixtures/operators/not_precedence.legacy.test +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -*, /, //, and % will have a higher precedence over not in Twig 4.0 ---DEPRECATION-- -Since twig/twig 3.15: Add explicit parentheses around the "not" unary operator to avoid behavior change in the next major version as its precedence will change in "index.twig" at line 2. ---TEMPLATE-- -{{ not 1 * 2 }} ---DATA-- -return [] ---EXPECT-- diff --git a/tests/Fixtures/operators/not_precedence.test b/tests/Fixtures/operators/not_precedence.test index 592b1c334..cca545f17 100644 --- a/tests/Fixtures/operators/not_precedence.test +++ b/tests/Fixtures/operators/not_precedence.test @@ -2,8 +2,9 @@ *, /, //, and % will have a higher precedence over not in Twig 4.0 --TEMPLATE-- {{ (not 1) * 2 }} -{{ (not 1 * 2) }} +{{ not 1 * 2 }} --DATA-- return [] --EXPECT-- 0 +0 diff --git a/tests/Fixtures/tests/null_coalesce.legacy.test b/tests/Fixtures/tests/null_coalesce.legacy.test deleted file mode 100644 index 3d33d0a79..000000000 --- a/tests/Fixtures/tests/null_coalesce.legacy.test +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -Twig supports the ?? operator ---DEPRECATION-- -Since twig/twig 3.15: Add explicit parentheses around the "??" binary operator to avoid behavior change in the next major version as its precedence will change in "index.twig" at line 4. -Since twig/twig 3.15: Add explicit parentheses around the "??" binary operator to avoid behavior change in the next major version as its precedence will change in "index.twig" at line 5. ---TEMPLATE-- -{{ nope ?? nada ?? 'OK' -}} {# no deprecation as the operators have the same precedence #} - -{{ 1 + nope ?? nada ?? 2 }} -{{ 1 + nope ?? 3 + nada ?? 2 }} ---DATA-- -return [] ---EXPECT-- -OK -3 -6 diff --git a/tests/Fixtures/tests/null_coalesce.test b/tests/Fixtures/tests/null_coalesce.test index f80b90717..5c034e260 100644 --- a/tests/Fixtures/tests/null_coalesce.test +++ b/tests/Fixtures/tests/null_coalesce.test @@ -13,6 +13,7 @@ Twig supports the ?? operator {{ nope ?? (nada ?? 'OK') }} {{ 1 + (nope ?? (nada ?? 2)) }} {{ 1 + (nope ?? 3) + (nada ?? 2) }} +{{ nope ?? nada ?? 2 }} --DATA-- return ['bar' => 'OK', 'foo' => ['bar' => 'OK']] --EXPECT-- @@ -28,3 +29,4 @@ OK OK 3 6 +2 \ No newline at end of file