Skip to content
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

Fix Jinjava functionality for duplicate macro functions and call tags #888

Closed
jasmith-hs opened this issue Jun 30, 2022 · 0 comments · Fixed by #889
Closed

Fix Jinjava functionality for duplicate macro functions and call tags #888

jasmith-hs opened this issue Jun 30, 2022 · 0 comments · Fixed by #889
Assignees

Comments

@jasmith-hs
Copy link
Contributor

{% macro foo() -%}
  first foo definition
{% endmacro %}
{% macro repeat(val) -%}
  {% print val %}
  {{ foo() }}
  {{ caller() }}
{% endmacro %}
{% call repeat(1) -%}
  1st caller
  {% macro foo() -%}
    second foo definition
  {% endmacro %}
  {% macro repeat(val) -%}
    {% print val %}
    {{ foo() }}
    {{ caller() }}
  {% endmacro %}
  {% for i in range(1) -%}
    {% macro foo() -%}
      third foo definition
    {% endmacro -%}
    {% call repeat(2) -%}
      2nd caller
    {% endcall %}
  {% endfor %}
{% endcall %}

The result is supposed to look like:

1
first foo definition

1st caller


2
third foo definition

2nd caller

But instead it looks like:

1
first foo definition

1st caller


2
second foo definition

1st caller


2
second foo definition

1st caller


2
second foo definition

1st caller


2
second foo definition

1st caller

There are 2 problems displayed in this example, the first is that the call tag is being overridden when the macro function's local context scope is being put on top of the current context. This overrides whatever macro functions that were defined within the same scope as the macro function with whatever their definition was at the time of the macro function being created. This overrides any macro functions that were defined in a lower level scope within the macro function.

This happening for the caller() macro is causing the infinite recursion (which gets stopped by max macro recursion depth).
This happening for the foo() macro is causing second foo definition to be output instead of third foo definition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant