Added ugly workaround for a loop bug.
authorArmin Ronacher <armin.ronacher@active-4.com>
Sun, 13 Sep 2009 06:48:18 +0000 (23:48 -0700)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sun, 13 Sep 2009 06:48:18 +0000 (23:48 -0700)
--HG--
branch : trunk

jinja2/compiler.py
tests/test_old_bugs.py

index 8adb83bb8f5e4b070d6776084a4f7ddf8e9c427e..f0deeff5f30922abb823ab3f8f318550024b2892 100644 (file)
@@ -647,6 +647,15 @@ class CodeGenerator(NodeVisitor):
         # macros are delayed, they never require output checks
         frame.require_output_check = False
         args = frame.arguments
+        # XXX: this is an ugly fix for the loop nesting bug
+        # (tests.test_old_bugs.test_loop_call_bug).  This works around
+        # a identifier nesting problem we have in general.  It's just more
+        # likely to happen in loops which is why we work around it.  The
+        # real solution would be "nonlocal" all the identifiers that are
+        # leaking into a new python frame and might be used both unassigned
+        # and assigned.
+        if 'loop' in frame.identifiers.declared:
+            args.append('l_loop=l_loop')
         self.writeline('def macro(%s):' % ', '.join(args), node)
         self.indent()
         self.buffer(frame)
index b004a29d06d5e0f5d4723d0e602d2daa7765940b..92fb43a7fd3c0927429a726f8f0f3e4ed3ddea06 100644 (file)
@@ -56,7 +56,7 @@ def test_loop_call_loop():
 
     ''')
 
-    assert tmpl.render() == ''
+    assert tmpl.render().split() == map(unicode, range(1, 11)) * 5
 
 
 def test_weird_inline_comment():