Permalink
Browse files

Fixed a scoping bug that caused the immutable scoping rule to be ignored

in a few edge cases.  This clauses #376.

--HG--
branch : trunk
  • Loading branch information...
1 parent 752ba7f commit 8a672512e7275985b8bc4be24b470c99a1be79ec @mitsuhiko mitsuhiko committed Apr 5, 2010
Showing with 16 additions and 3 deletions.
  1. +3 −3 jinja2/compiler.py
  2. +13 −0 jinja2/testsuite/regression.py
View
@@ -293,8 +293,7 @@ def visit_If(self, node):
self.visit(node.test)
real_identifiers = self.identifiers
- old_names = real_identifiers.declared | \
- real_identifiers.declared_locally | \
+ old_names = real_identifiers.declared_locally | \
real_identifiers.declared_parameter
def inner_visit(nodes):
@@ -315,7 +314,8 @@ def inner_visit(nodes):
# the differences between the two branches are also pulled as
# undeclared variables
- real_identifiers.undeclared.update(body.symmetric_difference(else_))
+ real_identifiers.undeclared.update(body.symmetric_difference(else_) -
+ real_identifiers.declared)
# remember those that are declared.
real_identifiers.declared_locally.update(body | else_)
@@ -162,6 +162,19 @@ def test_stacked_locals_scoping_bug(self):
''')
assert t.render(a=0, b=False, c=42, d=42.0) == '1111C'
+ def test_stacked_locals_scoping_bug_twoframe(self):
+ t = Template('''
+ {% set x = 1 %}
+ {% for item in foo %}
+ {% if item == 1 %}
+ {% set x = 2 %}
+ {% endif %}
+ {% endfor %}
+ {{ x }}
+ ''')
+ rv = t.render(foo=[1]).strip()
+ assert rv == u'1'
+
def test_call_with_args(self):
t = Template("""{% macro dump_users(users) -%}
<ul>

0 comments on commit 8a67251

Please sign in to comment.