From 5dbb42b3c4a770a03c54689b6f0cf09f989f6cef Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 25 Mar 2009 15:00:06 -0700 Subject: [PATCH] Fix bad self argument crash in cpdef methods (#165) --HG-- rename : tests/bugs/missing_self_in_cpdef_method_T165.pyx => tests/errors/missing_self_in_cpdef_method_T165.pyx --- Cython/Compiler/Nodes.py | 7 ++++++- tests/bugs/missing_self_in_cpdef_method_T165.pyx | 5 ----- tests/errors/missing_self_in_cpdef_method_T165.pyx | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) delete mode 100644 tests/bugs/missing_self_in_cpdef_method_T165.pyx create mode 100644 tests/errors/missing_self_in_cpdef_method_T165.pyx diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index d9254ad0..b30e29f7 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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 index 75349a87..00000000 --- a/tests/bugs/missing_self_in_cpdef_method_T165.pyx +++ /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 index 00000000..3b66bc72 --- /dev/null +++ b/tests/errors/missing_self_in_cpdef_method_T165.pyx @@ -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) +""" -- 2.26.2