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):
cpp_override_allowed = True
continue
# in a cypclass, if the arguments are compatible
# then the whole signature must be identical (return type excluded)
# Any inherited method is visible
# 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()
new_declarator = type.declarator_code(name, for_display = 1).strip()
if not new_declarator == old_declarator:
......@@ -565,9 +571,12 @@ class Scope(object):
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:
# also, the return type must be covariant
elif not type.return_type.subtype_of_resolved_type(alt_entry.type.return_type):
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)
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