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