Commit 8c9f6358 authored by Tom Niget's avatar Tom Niget

Fix inheritance unification

parent 422dd576
......@@ -40,6 +40,9 @@ class BaseType(ABC):
for p in cur.get_parents():
queue.put(p)
def inherits_from(self, other: "BaseType") -> bool:
return other in self.iter_hierarchy_recursive()
def resolve(self) -> "BaseType":
return self
......@@ -219,25 +222,27 @@ class TypeOperator(BaseType, ABC):
return other.unify_internal(self)
if self.is_protocol and not other.is_protocol:
return other.matches_protocol(self) # TODO: doesn't print the correct type in the error message
if len(self.args) < len(other.args):
return other.unify_internal(self)
assert self.is_protocol == other.is_protocol
if type(self) != type(other):
for parent in other.get_parents():
try:
self.unify(parent)
except TypeMismatchError:
pass
else:
return
for parent in self.get_parents():
try:
parent.unify(other)
except TypeMismatchError:
pass
else:
return
if type(self) != type(other): # and ((TY_NONE not in {self, other}) or isinstance(({self, other} - {TY_NONE}).pop(), UnionType)):
if self.inherits_from(other) or other.inherits_from(self):
return
# for parent in other.get_parents():
# try:
# self.unify(parent)
# except TypeMismatchError:
# pass
# else:
# return
# for parent in self.get_parents():
# try:
# parent.unify(other)
# except TypeMismatchError:
# pass
# else:
# return
raise TypeMismatchError(self, other, TypeMismatchKind.DIFFERENT_TYPE)
if len(self.args) < len(other.args):
return other.unify_internal(self)
if len(self.args) == 0:
if self.name != other.name:
raise TypeMismatchError(self, other, TypeMismatchKind.DIFFERENT_TYPE)
......
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