antlr / stringtemplate4

StringTemplate 4
http://www.stringtemplate.org
Other
956 stars 231 forks source link

Wrong behaviour when rendering loops depending on variable name #123

Closed aaguilera closed 6 years ago

aaguilera commented 9 years ago

I've observed a wrong behaviour in the following test case:

ST tpl = new ST("<names:{ i | <i> }>");
tpl.add("names", Arrays.asList("john", "peter"));
System.out.println(tpl.render());

The expected output would be:

john peter

But instead i get the following output:

context [anonymous] 1:7 passed 1 arg(s) to template /_sub1 with 0 declared arg(s)
1 2 

As you see (apart from the warning message) we get 1 2 instead of john peter. But if we use other variable name inside the loop (u instead of i, for example, <names:{ u | <u> }>) then we get the expected output john peter.

parrt commented 6 years ago

i and i0 are reserved variables.