Skip to content

MacroNode $name argument overriden in constructor loop ? #4515

@smnandre

Description

@smnandre

In MacroNode constructor, the $name argument can be overridden by the last "key" of the $argments argument

    //                                     🟢 
    public function __construct(string $name, Node $body, Node $arguments, int $lineno)
    {
         // ...

        if (!$arguments instanceof ArrayExpression) {
             // ...
            
            //                       🟢 
            foreach ($arguments as $name => $default) { 
                $args->addElement($default, new LocalVariable($name, $default->getTemplateLine()));
            }

            // ...
        }

        // ...
        //                                                                            🟢 
        parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno);
    }

public function __construct(string $name, Node $body, Node $arguments, int $lineno)
{
if (!$body instanceof BodyNode) {
trigger_deprecation('twig/twig', '3.12', \sprintf('Not passing a "%s" instance as the "body" argument of the "%s" constructor is deprecated ("%s" given).', BodyNode::class, static::class, $body::class));
}
if (!$arguments instanceof ArrayExpression) {
trigger_deprecation('twig/twig', '3.15', \sprintf('Not passing a "%s" instance as the "arguments" argument of the "%s" constructor is deprecated ("%s" given).', ArrayExpression::class, static::class, $arguments::class));
$args = new ArrayExpression([], $arguments->getTemplateLine());
foreach ($arguments as $name => $default) {
$args->addElement($default, new LocalVariable($name, $default->getTemplateLine()));
}
$arguments = $args;
}
foreach ($arguments->getKeyValuePairs() as $pair) {
if ("\u{035C}".self::VARARGS_NAME === $pair['key']->getAttribute('name')) {
throw new SyntaxError(\sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $pair['value']->getTemplateLine(), $pair['value']->getSourceContext());
}
}
parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno);
}

Not sure if this has any real occurence / consequence... if no sorry for the waste of time 🤷

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions