Add return type to compiled macro

This makes it easier for TwigStan to analyze the return type.
This commit is contained in:
Ruud Kamphuis
2024-10-24 13:51:09 +02:00
parent b0017ad8c3
commit 1e7c719e24
2 changed files with 4 additions and 3 deletions
+2 -1
View File
@@ -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")
+2 -2
View File
@@ -49,7 +49,7 @@ class MacroTest extends NodeTestCase
yield 'with use_yield = true' => [$node, <<<EOF
// line 1
public function macro_foo(\$foo = null, \$bar = "Foo", ...\$varargs)
public function macro_foo(\$foo = null, \$bar = "Foo", ...\$varargs): string|Markup
{
\$macros = \$this->macros;
\$context = [
@@ -71,7 +71,7 @@ EOF
yield 'with use_yield = false' => [$node, <<<EOF
// line 1
public function macro_foo(\$foo = null, \$bar = "Foo", ...\$varargs)
public function macro_foo(\$foo = null, \$bar = "Foo", ...\$varargs): string|Markup
{
\$macros = \$this->macros;
\$context = [