Twig icon indicating copy to clipboard operation
Twig copied to clipboard

Mark implicit macro argument default values as such with an attribute

Open drjayvee opened this issue 11 months ago • 1 comments

This change causes no difference to compiled templates or to macro argument semantics.

Consider the following macro:

{% macro marco(po, lo = null) %}{% endmacro %}

With this change, the ConstantExpression for argument po will have an attribute isImplicit, whose value will be true. (Note that lo will not have that attribute.)

This allows node visitors to distinguish between arguments that do and those that do not have explicit default values even if the value is null.

This is useful for static code analysis.

For example, a static analysis tool might consider arguments with no explicit default value as non-optional.

drjayvee avatar Mar 16 '24 15:03 drjayvee

Similar to #4009, this is a prerequisite for a desired static analysis inspection in TwigStan.

I can extend this feature by adding this attribute to every function/macro argument to make it more consistent.

drjayvee avatar Mar 16 '24 15:03 drjayvee

@fabpot thanks for the review. The latest commit includes all your suggestions.

drjayvee avatar Aug 20 '24 10:08 drjayvee

@fabpot since you're working on Twig these days, could you please have another look at this PR? 😊

drjayvee avatar Aug 27 '24 10:08 drjayvee

Thank you @drjayvee.

fabpot avatar Aug 27 '24 11:08 fabpot

Merged.

fabpot avatar Aug 27 '24 11:08 fabpot