Commit d8ffa16c authored by Vitja Makarov's avatar Vitja Makarov

Raise correct exception if entry came from closure

parent bf1e2133
...@@ -1420,11 +1420,16 @@ class CCodeWriter(object): ...@@ -1420,11 +1420,16 @@ class CCodeWriter(object):
return self.putln("if (%s < 0) %s" % (value, self.error_goto(pos))) return self.putln("if (%s < 0) %s" % (value, self.error_goto(pos)))
def put_error_if_unbound(self, pos, entry): def put_error_if_unbound(self, pos, entry):
self.put('if (unlikely(!%s)) { ' self.put('if (unlikely(!%s)) { PyErr_SetString(' % entry.cname)
'PyErr_SetString(PyExc_UnboundLocalError, "' if entry.from_closure:
"local variable '%s' referenced before assignment" self.put('PyExc_NameError, "')
'"); %s }' % self.put("free variable '%s' referenced before assignment in enclosing scope" %
(entry.cname, entry.name, self.error_goto(pos))) entry.name)
else:
self.put('PyExc_UnboundLocalError, "')
self.put("local variable '%s' referenced before assignment" %
entry.name)
self.putln('"); %s }' % self.error_goto(pos))
def set_error_info(self, pos): def set_error_info(self, pos):
self.funcstate.should_declare_error_indicator = True self.funcstate.should_declare_error_indicator = True
......
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