From 1e7c719e24eb318ae67a1added4b361cb499ff8e Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Thu, 24 Oct 2024 13:51:09 +0200 Subject: [PATCH] Add return type to compiled macro This makes it easier for TwigStan to analyze the return type. --- src/Node/MacroNode.php | 3 ++- tests/Node/MacroTest.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Node/MacroNode.php b/src/Node/MacroNode.php index 5ada1b220..d96e98cf2 100644 --- a/src/Node/MacroNode.php +++ b/src/Node/MacroNode.php @@ -14,6 +14,7 @@ namespace Twig\Node; use Twig\Attribute\YieldReady; use Twig\Compiler; use Twig\Error\SyntaxError; +use Twig\Markup; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\Variable\LocalVariable; @@ -76,7 +77,7 @@ class MacroNode extends Node $compiler ->raw('...$varargs') - ->raw(")\n") + ->raw("): string|Markup\n") ->write("{\n") ->indent() ->write("\$macros = \$this->macros;\n") diff --git a/tests/Node/MacroTest.php b/tests/Node/MacroTest.php index 39ff9cd1f..fcd5db402 100644 --- a/tests/Node/MacroTest.php +++ b/tests/Node/MacroTest.php @@ -49,7 +49,7 @@ class MacroTest extends NodeTestCase yield 'with use_yield = true' => [$node, <<macros; \$context = [ @@ -71,7 +71,7 @@ EOF yield 'with use_yield = false' => [$node, <<macros; \$context = [