Commit 173b578c authored by Vitja Makarov's avatar Vitja Makarov

Fix control-flow and closure entries

parent 3a89c5a0
......@@ -1556,7 +1556,7 @@ class NameNode(AtomicExprNode):
code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.py_result())
elif entry.is_local:
elif entry.is_local or entry.in_closure or entry.from_closure:
if entry.type.is_pyobject:
if (self.cf_maybe_null or self.cf_is_null) and not self.allow_null:
code.putln('if (unlikely(!%s)) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }' %
......@@ -1635,14 +1635,14 @@ class NameNode(AtomicExprNode):
code.put_xgotref(self.py_result())
else:
code.put_gotref(self.py_result())
if entry.is_local:
if entry.is_cglobal:
code.put_decref(self.result(), self.ctype())
else:
if not self.cf_is_null:
if self.cf_maybe_null:
code.put_xdecref(self.result(), self.ctype())
else:
code.put_decref(self.result(), self.ctype())
else:
code.put_decref(self.result(), self.ctype())
if is_external_ref:
code.put_giveref(rhs.py_result())
......
......@@ -473,9 +473,11 @@ def check_definitions(flow, compiler_directives):
for node, entry in references.iteritems():
if Uninitialized in node.cf_state:
node.cf_maybe_null = True
if entry.from_closure or node.allow_null:
if not entry.from_closure and len(node.cf_state) == 1:
node.cf_is_null = True
if node.allow_null or entry.from_closure:
pass # Can be uninitialized here
elif len(node.cf_state) == 1:
elif node.cf_is_null:
if entry.type.is_pyobject or entry.type.is_unspecified:
messages.error(
node.pos,
......@@ -486,9 +488,7 @@ def check_definitions(flow, compiler_directives):
node.pos,
"local variable '%s' referenced before assignment"
% entry.name)
node.cf_is_null = True
else:
if warn_maybe_uninitialized:
elif warn_maybe_uninitialized:
messages.warning(
node.pos,
"local variable '%s' might be referenced before assignment"
......
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