Fixed iterator raising exception bug.
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Wed, 14 May 2008 19:58:07 +0000 (21:58 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Wed, 14 May 2008 19:58:07 +0000 (21:58 +0200)
Simply a typo in NextNode...

Cython/Compiler/ExprNodes.py
tests/run/iteratorexception.pyx [new file with mode: 0644]

index 2a95b4f2c75ea777cec82ca83f7baadfaffc4950..47b94ba676bdc87bc649eae7ca9fbd4a72fe4448 100644 (file)
@@ -1197,7 +1197,7 @@ class NextNode(AtomicExprNode):
         code.putln(
             "if (!%s) {" %
                 self.result_code)
-        code.error_goto_if_PyErr(self.pos)
+        code.putln(code.error_goto_if_PyErr(self.pos))
         code.putln("break;")
         code.putln("}")
         code.putln("}")
diff --git a/tests/run/iteratorexception.pyx b/tests/run/iteratorexception.pyx
new file mode 100644 (file)
index 0000000..98f9806
--- /dev/null
@@ -0,0 +1,17 @@
+__doc__ = """
+    >>> f()
+"""
+
+class IteratorAndIterateable:
+    def next(self):
+        raise ValueError("")
+    def __iter__(self):
+        return self
+
+def f():
+    try:
+        for x in IteratorAndIterateable():
+            pass
+        assert False, "Should not reach this point, iterator has thrown exception"
+    except ValueError:
+        pass