Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: translation-cleanup
Changeset: r58015:76950b0447c5
Date: 2012-10-11 14:39 +0100
http://bitbucket.org/pypy/pypy/changeset/76950b0447c5/

Log:    Raise FlowingError for run-time UnboundLocalError

diff --git a/pypy/objspace/flow/flowcontext.py 
b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -668,6 +668,12 @@
         else:
             self.space.call_function(w_exitfunc, w_None, w_None, w_None)
 
+    def LOAD_FAST(self, varindex, next_instr):
+        w_value = self.locals_stack_w[varindex]
+        if w_value is None:
+            raise FlowingError(self, "Local variable referenced before 
assignment")
+        self.pushvalue(w_value)
+
     def LOAD_GLOBAL(self, nameindex, next_instr):
         w_result = self.space.find_global(self.w_globals, 
self.getname_u(nameindex))
         self.pushvalue(w_result)
diff --git a/pypy/objspace/flow/test/test_objspace.py 
b/pypy/objspace/flow/test/test_objspace.py
--- a/pypy/objspace/flow/test/test_objspace.py
+++ b/pypy/objspace/flow/test/test_objspace.py
@@ -1122,6 +1122,12 @@
             self.codetest(f)
         assert "closure" in str(excinfo.value)
 
+    def test_unbound_local(self):
+        def f():
+            x += 1
+        with py.test.raises(FlowingError):
+            self.codetest(f)
+
 DATA = {'x': 5,
         'y': 6}
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to