Commit 0da5c3e1 authored by Xavier Thompson's avatar Xavier Thompson

Detect non-covariant return types in overriding cypclass methods

parent cdfe4a08
...@@ -554,8 +554,14 @@ class Scope(object): ...@@ -554,8 +554,14 @@ class Scope(object):
cpp_override_allowed = True cpp_override_allowed = True
continue continue
# in a cypclass, if the arguments are compatible # Any inherited method is visible
# then the whole signature must be identical (return type excluded) # until overloaded by a method with the same signature
if alt_entry.is_inherited:
if self.is_cyp_class_scope:
# in a cypclass, if the arguments are compatible, then the new method must actually
# override the inherited method: the whole signature must be identical
old_declarator = alt_entry.type.declarator_code(name, for_display = 1).strip() old_declarator = alt_entry.type.declarator_code(name, for_display = 1).strip()
new_declarator = type.declarator_code(name, for_display = 1).strip() new_declarator = type.declarator_code(name, for_display = 1).strip()
if not new_declarator == old_declarator: if not new_declarator == old_declarator:
...@@ -565,9 +571,12 @@ class Scope(object): ...@@ -565,9 +571,12 @@ class Scope(object):
if alt_entry.pos is not None: if alt_entry.pos is not None:
error(alt_entry.pos, "Conflicting method is defined here") error(alt_entry.pos, "Conflicting method is defined here")
# Any inherited method is visible # also, the return type must be covariant
# until overloaded by a method with the same signature elif not type.return_type.subtype_of_resolved_type(alt_entry.type.return_type):
if alt_entry.is_inherited: error(pos, "Cypclass method overrides another with incompatible return type")
if alt_entry.pos is not None:
error(alt_entry.pos, "Conflicting method is defined here")
previous_alternative_indices.append(index) previous_alternative_indices.append(index)
cpp_override_allowed = True cpp_override_allowed = True
continue 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