Open agate-pris opened 2 years ago
It may be self-resolving.
It can explicitly interrupt the loop by changing. It will be seen that the result is different from my expectation.
{%- import "macros.txt" as macros -%}
{%- set n = 5 -%}
{{- macros::r(n=n, name=name, schema=schema) -}}
{%- macro r(n, name, schema) -%}
{%- if n > 0 -%}
{{ name }}
{%- if schema.properties -%}
{%- for name, schema in schema.properties %}
{{ self::r(n=n-1, name=name, schema=schema) }}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
a
foo
foo
foo
foo
OK, it resolved.
I have found that if the outer name of a macro call conflicts with the name of the macro argument, the outer name of a macro call takes precedence.
This can have unexpected results.
If this is the intended design, please close this issue.
Thank you.
{%- import "macros.txt" as macros -%}
{{- macros::r(arg_name=name, arg_schema=schema) -}}
{%- macro r(arg_name, arg_schema) -%}
{{ arg_name }}
{%- if arg_schema.properties -%}
{%- for name, schema in schema.properties %}
{{ self::r(arg_name=name, arg_schema=schema) }}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}
Hi!
My recursive macro call causes unexpected stack overflow.
I have followed the official documentation and wrote template carefully so that infinite recursion does not occur. I am not sure what I am doing wrong.
Can someone please tell me what is wrong with the following template?