-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Mark implicit macro argument default values as such with an attribute in AST #4010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This change causes no difference to compiled templates or to macro argument semantics.
Consider the following macro:
```twig
{% 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](twigphp#4003).
For example, a static analysis tool might consider arguments with no explicit default value as non-optional.
Contributor
Author
fabpot
reviewed
Aug 19, 2024
Contributor
Author
|
@fabpot thanks for the review. The latest commit includes all your suggestions. |
Contributor
Author
|
@fabpot since you're working on Twig these days, could you please have another look at this PR? 😊 |
fabpot
requested changes
Aug 27, 2024
Contributor
fabpot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Contributor
|
Thank you @drjayvee. |
fabpot
added a commit
that referenced
this pull request
Aug 27, 2024
…h an attribute in AST (drjayvee)
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Mark implicit macro argument default values as such with an attribute in AST
This change causes no difference to compiled templates or to macro argument semantics.
Consider the following macro:
```twig
{% macro marco(po, lo = null) %}{% endmacro %}
```
With this change, the `ConstantExpression` for argument `po` will have an attribute `is_implicit`, 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](#4003).
For example, a static analysis tool might consider arguments with no explicit default value as non-optional.
Commits
-------
e83a802 Mark implicit macro argument default values as such with an attribute in AST
Contributor
|
Merged. |
drjayvee
added a commit
to alisqi/TwigQI
that referenced
this pull request
Aug 28, 2024
To preview twigphp/Twig#4010
alizfara112
added a commit
to alizfara112/TwigQI
that referenced
this pull request
Jun 10, 2025
To preview twigphp/Twig#4010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
ConstantExpressionfor argumentpowill have an attributeis_implicit, whose value will betrue. (Note thatlowill 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.