Ticket 135 (return statement outside a function body crashes cython)
can be fixed with a simple assignment of None to self.return_type in
the Scope __init__ function.  The crash happens when there is a return
statement in the class body as well as at the module level.

Every function object explicitly assigns something else to the scope's
return_type, so the function objects are not affected by this change.

Here's the diff with a test case included.  I included this on the
trac page, but thought it would be easiest to get it pushed here.

diff -r e2365a6d00b8 -r f153d2da27b0 Cython/Compiler/Symtab.py
--- a/Cython/Compiler/Symtab.py Tue Mar 17 07:32:51 2009 +0100
+++ b/Cython/Compiler/Symtab.py Tue Mar 17 15:10:14 2009 -0500
@@ -235,6 +235,7 @@ class Scope(object):
         self.pystring_entries = []
         self.buffer_entries = []
         self.control_flow = ControlFlow.LinearControlFlow()
+        self.return_type = None

     def start_branching(self, pos):
         self.control_flow = self.control_flow.start_branch(pos)
diff -r e2365a6d00b8 -r f153d2da27b0
tests/errors/return_outside_function_T135.pyx
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/errors/return_outside_function_T135.pyx     Tue Mar 17
15:10:14 2009 -0500
@@ -0,0 +1,12 @@
+return 'bar'
+class A:
+    return None
+
+cdef class B:
+    return None
+
+_ERRORS = u'''
+1:0: Return not inside a function body
+3:4: Return not inside a function body
+6:4: Return not inside a function body
+'''
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to