Commits

Ronan Lamy committed 8d2a95a

Fix exception raising

  • Participants
  • Parent commits 3a5b76c
  • Branches less-stringly-ops

Comments (0)

Files changed (2)

rpython/flowspace/flowcontext.py

                 raise const(TypeError(
                     "raise: no active exception to re-raise"))
 
-        w_value = space.w_None
         if nbargs >= 3:
             self.popvalue()
         if nbargs >= 2:
             w_value = self.popvalue()
-        if 1:
             w_type = self.popvalue()
-        operror = space.exc_from_raise(w_type, w_value)
+            operror = space.exc_from_raise(w_type, w_value)
+        else:
+            w_type = self.popvalue()
+            if isinstance(w_type, FSException):
+                operror = w_type
+            else:
+                operror = space.exc_from_raise(w_type, space.w_None)
         raise operror
 
     def IMPORT_NAME(self, nameindex):

rpython/flowspace/test/test_objspace.py

         assert x.startblock.exits[0].args == [ops[1].result, ops[0].result]
         assert x.startblock.exits[0].target is x.exceptblock
 
+    def test_simple_raise(self):
+        def f():
+            raise ValueError('ouch')
+        x = self.codetest(f)
+        simplify_graph(x)
+        self.show(x)
+        ops = x.startblock.operations
+        assert ops[0].opname == 'simple_call'
+        assert ops[0].args == [Constant(ValueError), Constant('ouch')]
+
     #__________________________________________________________
     def raise2(msg):
         raise IndexError, msg