Commit 9906ab9c authored by Robert Bradshaw's avatar Robert Bradshaw

Allow undeclared narrower return for cdef methods.

parent 68a4db26
......@@ -2553,11 +2553,11 @@ class CFuncType(CType):
def as_argument_type(self):
return c_ptr_type(self)
def same_c_signature_as(self, other_type, as_cmethod = 0):
def same_c_signature_as(self, other_type, as_cmethod = 0, as_pxd_definition = 0):
return self.same_c_signature_as_resolved_type(
other_type.resolve(), as_cmethod)
def same_c_signature_as_resolved_type(self, other_type, as_cmethod = 0):
def same_c_signature_as_resolved_type(self, other_type, as_cmethod = 0, as_pxd_definition = 0):
#print "CFuncType.same_c_signature_as_resolved_type:", \
# self, other_type, "as_cmethod =", as_cmethod ###
if other_type is error_type:
......@@ -2579,8 +2579,13 @@ class CFuncType(CType):
return 0
if self.optional_arg_count != other_type.optional_arg_count:
return 0
if not self.return_type.same_as(other_type.return_type):
return 0
if as_pxd_definition:
# A narrowing of the return type declared in the pxd is allowed.
if not self.return_type.subtype_of_resolved_type(other_type.return_type):
return 0
else:
if not self.return_type.same_as(other_type.return_type):
return 0
if not self.same_calling_convention_as(other_type):
return 0
if self.exception_check != other_type.exception_check:
......
......@@ -2094,7 +2094,8 @@ class CClassScope(ClassScope):
# Fix with_gil vs nogil.
entry.type = entry.type.with_with_gil(type.with_gil)
elif type.compatible_signature_with(entry.type, as_cmethod = 1) and type.nogil == entry.type.nogil:
if self.defined and not in_pxd:
if (self.defined and not in_pxd
and not type.same_c_signature_as_resolved_type(entry.type, as_cmethod = 1, as_pxd_definition = 1)):
error(pos,
"Compatible but non-identical C method '%s' not redeclared "
"in definition part of extension type '%s'" % (name, self.class_name))
......
......@@ -6,3 +6,6 @@ cdef class MissingRedeclaration(Base):
cdef class BadRedeclaration(Base):
cdef f(self)
cdef class NarrowerReturn(Base):
pass
......@@ -28,6 +28,11 @@ cdef class UnneededRedeclaration(Base):
cpdef f(self):
pass
cdef class NarrowerReturn(Base):
# This does not require a new vtable entry.
cdef Base f(self):
pass
_ERRORS = u"""
8: 9: Signature not compatible with previous declaration
......
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