# 1.cr
{% for name, index in ["foo", "bar", "baz"] %}
def {{name.id}}
{{index}}
end
{% debug %}
{% end %}
The output of crystal run 1.cr
is:
def foo
0
end
def foo
0
end
def bar
1
end
def foo
0
end
def bar
1
end
def baz
2
end
As above, the method foo
has been defined 3 times, method bar
defined 2 times, method baz
define 1 times.
The correct(expected) result is each method should only be defined once, right?
def foo
0
end
def bar
1
end
def baz
2
end
Is it for loop doing something wrong, or {% debug%}
?
╰─ $ crystal version
Crystal 1.13.1 [0cef61e51] (2024-07-12)
LLVM: 18.1.8
Default target: x86_64-pc-linux-gnu