Fix bad self argument crash in cpdef methods (#165)
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 25 Mar 2009 22:00:06 +0000 (15:00 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 25 Mar 2009 22:00:06 +0000 (15:00 -0700)
--HG--
rename : tests/bugs/missing_self_in_cpdef_method_T165.pyx => tests/errors/missing_self_in_cpdef_method_T165.pyx

Cython/Compiler/Nodes.py
tests/bugs/missing_self_in_cpdef_method_T165.pyx [deleted file]
tests/errors/missing_self_in_cpdef_method_T165.pyx [new file with mode: 0644]

index d9254ad0ad7709b871edcaa6c391de3ea14c632d..b30e29f7217282a16eae4727dcb6a555e56b966f 100644 (file)
@@ -1337,7 +1337,12 @@ class CFuncDefNode(FuncDefNode):
         self.entry.inline_func_in_pxd = self.inline_in_pxd
         self.return_type = type.return_type
         
-        if self.overridable and len(self.args) > 0:
+        if self.overridable and not env.is_module_scope:
+            if len(self.args) < 1 or not self.args[0].type.is_pyobject:
+                # An error will be produced in the cdef function
+                self.overridable = False
+            
+        if self.overridable:
             import ExprNodes
             py_func_body = self.call_self_node(is_module_scope = env.is_module_scope)
             self.py_func = DefNode(pos = self.pos, 
diff --git a/tests/bugs/missing_self_in_cpdef_method_T165.pyx b/tests/bugs/missing_self_in_cpdef_method_T165.pyx
deleted file mode 100644 (file)
index 75349a8..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-
-cdef class A:
-    cpdef a(int not_self):
-        pass
-
diff --git a/tests/errors/missing_self_in_cpdef_method_T165.pyx b/tests/errors/missing_self_in_cpdef_method_T165.pyx
new file mode 100644 (file)
index 0000000..3b66bc7
--- /dev/null
@@ -0,0 +1,8 @@
+
+cdef class A:
+    cpdef a(int not_self):
+        pass
+
+_ERRORS = u"""
+3:10: Self argument (int) of C method 'a' does not match parent type (A)
+"""