Commit 9f7256fd authored by Vitja Makarov's avatar Vitja Makarov

CF: reference doesn't mean it's not null

parent 12410403
...@@ -193,9 +193,11 @@ class ControlFlow(object): ...@@ -193,9 +193,11 @@ class ControlFlow(object):
def mark_reference(self, node, entry): def mark_reference(self, node, entry):
if self.block and self.is_tracked(entry): if self.block and self.is_tracked(entry):
self.block.stats.append(NameReference(node, entry)) self.block.stats.append(NameReference(node, entry))
# Local variable is definitely bound after this reference ## XXX: We don't track expression evaluation order so we can't use
if not node.allow_null: ## XXX: successful reference as initialization sign.
self.block.bounded.add(entry) ## # Local variable is definitely bound after this reference
## if not node.allow_null:
## self.block.bounded.add(entry)
self.entries.add(entry) self.entries.add(entry)
def normalize(self): def normalize(self):
...@@ -548,9 +550,9 @@ def check_definitions(flow, compiler_directives): ...@@ -548,9 +550,9 @@ def check_definitions(flow, compiler_directives):
references[stat.node] = stat.entry references[stat.node] = stat.entry
stat.entry.cf_references.append(stat) stat.entry.cf_references.append(stat)
stat.node.cf_state.update(state) stat.node.cf_state.update(state)
if not stat.node.allow_null: ## if not stat.node.allow_null:
i_state &= ~i_assmts.bit ## i_state &= ~i_assmts.bit
# after successful read, the state is known to be initialised ## # after successful read, the state is known to be initialised
state.discard(Uninitialized) state.discard(Uninitialized)
state.discard(Unknown) state.discard(Unknown)
for assmt in state: for assmt in state:
......
...@@ -163,3 +163,17 @@ def test_try_finally_regression(c): ...@@ -163,3 +163,17 @@ def test_try_finally_regression(c):
return a return a
finally: finally:
return a return a
def test_expression_calculation_order_bug(a):
"""
>>> test_expression_calculation_order_bug(False)
[]
>>> test_expression_calculation_order_bug(True)
Traceback (most recent call last):
...
UnboundLocalError: local variable 'b' referenced before assignment
"""
if not a:
b = []
return (a or b) and (b or a)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment