Commit e9d9d2d8 authored by Xavier Thompson's avatar Xavier Thompson

Enforce stricter cypclass overloading rules

parent fefd5c56
......@@ -3096,8 +3096,8 @@ class CFuncType(CType):
return rhs_type.same_c_signature_as_resolved_type(self, exact_semantics=False) \
and not (self.nogil and not rhs_type.nogil)
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0,
def declarator_code(self, entity_code,
for_display = 0, pyrex = 0,
with_calling_convention = 1):
arg_decl_list = []
for arg in self.args[:len(self.args)-self.optional_arg_count]:
......@@ -3134,9 +3134,13 @@ class CFuncType(CType):
cc = ""
if self.is_const_method:
trailer += " const"
return self.return_type.declaration_code(
"%s%s(%s)%s" % (cc, entity_code, arg_decl_code, trailer),
for_display, dll_linkage, pyrex)
return "%s%s(%s)%s" % (cc, entity_code, arg_decl_code, trailer)
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0,
with_calling_convention = 1):
declarator_code = self.declarator_code(entity_code, for_display, pyrex, with_calling_convention)
return self.return_type.declaration_code(declarator_code, for_display, dll_linkage, pyrex)
def function_header_code(self, func_name, arg_code):
if self.is_const_method:
......
......@@ -554,28 +554,20 @@ class Scope(object):
cpp_override_allowed = True
continue
# in a cypclass, if the arguments are compatible
# then the whole signature must be identical (return type excluded)
old_declarator = alt_entry.type.declarator_code(name, for_display = 1).strip()
new_declarator = type.declarator_code(name, for_display = 1).strip()
if not new_declarator == old_declarator:
comparison_message = " ---> %s\nvs -> %s" % (new_declarator, old_declarator)
error(pos, "Cypclass method with compatible arguments but incompatible signature:\n%s"
% comparison_message)
if alt_entry.pos is not None:
error(alt_entry.pos, "Conflicting method is defined here")
# Any inherited method is visible
# until overloaded by a method with the same signature
if alt_entry.is_inherited:
# in a cypclass, if the arguments are compatible
# then the whole signature must also be compatible
if self.is_cyp_class_scope:
if not type.compatible_signature_with(alt_entry.type, skip_args=1):
error(pos, "Cypclass overriding method with incompatible return type")
if alt_entry.pos is not None:
error(alt_entry.pos, "Overriden method is defined here")
# 'CFuncType.compatible_signature_with' doesn't compare constness, so we're doing it here.
# TODO: Maybe it should.
elif (type.is_const_method and not alt_entry.type.is_const_method
or not type.is_const_method and alt_entry.type.is_const_method):
print(type.is_const_method)
print(alt_entry.type.is_const_method)
error(pos, "Cypclass overriding method with conflicting constness")
if alt_entry.pos is not None:
error(alt_entry.pos, "Overriden method is defined here")
previous_alternative_indices.append(index)
cpp_override_allowed = True
continue
......
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