diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index db6b1555031..23b24aee26a 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -95,14 +95,18 @@ public function parseExpression($precedence = 0, $allowArrow = false) if ( ($expr instanceof AddBinary || $expr instanceof SubBinary) - && - ( - ($expr->getNode('left') instanceof ConcatBinary && !$expr->getNode('left')->hasExplicitParentheses()) - || - ($expr->getNode('right') instanceof ConcatBinary && !$expr->getNode('right')->hasExplicitParentheses()) - ) ) { - trigger_deprecation('twig/twig', '3.15', \sprintf('As "+" / "-" will have a higher precedence than "~" in Twig 4.0, please add parentheses to keep the current behavior in "%s" at line %d.', $this->parser->getStream()->getSourceContext()->getName(), $token->getLine())); + /** @var AbstractExpression $left */ + $left = $expr->getNode('left'); + /** @var AbstractExpression $right */ + $right = $expr->getNode('right'); + if ( + ($left instanceof ConcatBinary && !$left->hasExplicitParentheses()) + || + ($right instanceof ConcatBinary && !$right->hasExplicitParentheses()) + ) { + trigger_deprecation('twig/twig', '3.15', \sprintf('As "+" / "-" will have a higher precedence than "~" in Twig 4.0, please add parentheses to keep the current behavior in "%s" at line %d.', $this->parser->getStream()->getSourceContext()->getName(), $token->getLine())); + } } if (0 === $precedence) {