From 8ca4866a95d403ff30dbb09a5d11a20a1d4c5a74 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 Aug 2026 17:35:03 +0200 Subject: [PATCH] Clarify duplicate macro deprecation message --- src/Parser.php | 2 +- tests/Fixtures/macros/duplicate_definition.legacy.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 9f0c483fd46..42362dd3bf8 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -313,7 +313,7 @@ public function hasMacro(string $name): bool public function setMacro(string $name, MacroNode $node): void { if (isset($this->macros[$name])) { - trigger_deprecation('twig/twig', '3.29', 'Defining the macro "%s" more than once in "%s" is deprecated and will throw a SyntaxError in Twig 4.0 (first definition at line %d, second at line %d).', $name, $this->stream->getSourceContext()->getName(), $this->macros[$name]->getTemplateLine(), $node->getTemplateLine()); + trigger_deprecation('twig/twig', '3.29', 'Defining the macro "%s" more than once in "%s" is deprecated and will throw a SyntaxError in Twig 4.0 (first definition at line %d, second at line %d). The last definition is used in Twig 3.', $name, $this->stream->getSourceContext()->getName(), $this->macros[$name]->getTemplateLine(), $node->getTemplateLine()); } $this->macros[$name] = $node; diff --git a/tests/Fixtures/macros/duplicate_definition.legacy.test b/tests/Fixtures/macros/duplicate_definition.legacy.test index 8661e47781e..a0fb17000c2 100644 --- a/tests/Fixtures/macros/duplicate_definition.legacy.test +++ b/tests/Fixtures/macros/duplicate_definition.legacy.test @@ -1,7 +1,7 @@ --TEST-- Defining a macro more than once is deprecated --DEPRECATION-- -Since twig/twig 3.29: Defining the macro "greet" more than once in "index.twig" is deprecated and will throw a SyntaxError in Twig 4.0 (first definition at line 3, second at line 4). +Since twig/twig 3.29: Defining the macro "greet" more than once in "index.twig" is deprecated and will throw a SyntaxError in Twig 4.0 (first definition at line 3, second at line 4). The last definition is used in Twig 3. --TEMPLATE-- {% import _self as macros %} {% macro greet() %}first{% endmacro %}