Commit 7f22634d authored by Vitja Makarov's avatar Vitja Makarov

Disallow final cpdef methods in non-final extension type

parent 128eb184
......@@ -2244,7 +2244,11 @@ class DefNode(FuncDefNode):
#print "DefNode.declare_pyfunction:", self.name, "in", env ###
name = self.name
entry = env.lookup_here(name)
if entry and entry.type.is_cfunction and not entry.is_builtin_cmethod and not self.is_wrapper:
if entry:
if entry.is_final_cmethod and not env.parent_type.is_final_type:
error(self.pos, "Only final type could have final cpdef method")
if (entry.type.is_cfunction and not entry.is_builtin_cmethod
and not self.is_wrapper):
warning(self.pos, "Overriding cdef method with def method.", 5)
entry = env.declare_pyfunction(name, self.pos, allow_redefine=not self.is_wrapper)
self.entry = entry
......
......@@ -16,10 +16,7 @@ cdef class SubType(BaseClass):
cdef cdef_method(self):
pass
cpdef cpdef_method(self):
pass
_ERRORS = """
11:10: Only final type could have final cpdef method
16:9: Overriding final methods is not allowed
19:10: Overriding final methods is not allowed
"""
......@@ -3,21 +3,20 @@
cimport cython
cdef class FinalMethods(object):
@cython.final
cdef class FinalType(object):
"""
>>> obj = FinalMethods()
>>> obj = FinalType()
>>> obj.test_cdef()
>>> obj.test_cpdef()
"""
@cython.test_assert_path_exists("//CFuncDefNode[@entry.is_final_cmethod=True]")
@cython.final
cdef cdef_method(self):
pass
@cython.test_assert_path_exists("//CFuncDefNode[@entry.is_final_cmethod=True]")
@cython.test_fail_if_path_exists("//CFuncDefNode//OverrideCheckNode")
@cython.final
cpdef cpdef_method(self):
pass
......@@ -30,16 +29,27 @@ cdef class FinalMethods(object):
self.cpdef_method()
cdef class SubType(FinalMethods):
cdef class BaseTypeWithFinalMethods(object):
"""
>>> obj = SubType()
>>> obj = BaseTypeWithFinalMethods()
>>> obj.test_cdef()
>>> obj.test_cpdef()
"""
@cython.test_assert_path_exists("//CFuncDefNode[@entry.is_final_cmethod=True]")
@cython.final
cdef cdef_method(self):
pass
@cython.test_assert_path_exists("//AttributeNode[@entry.is_final_cmethod=True]")
def test_cdef(self):
self.cdef_method()
cdef class SubType(BaseTypeWithFinalMethods):
"""
>>> obj = SubType()
>>> obj.test_cdef()
"""
@cython.test_assert_path_exists("//AttributeNode[@entry.is_final_cmethod=True]")
def test_cpdef(self):
self.cpdef_method()
def test_cdef(self):
self.cdef_method()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment