fix: sub-unification bug

This commit is contained in:
Shunsuke Shibayama 2023-03-17 12:53:56 +09:00
parent bda30ecbe2
commit 8bccc6b487
2 changed files with 19 additions and 0 deletions

View file

@ -658,6 +658,24 @@ impl Context {
}
Ok(())
}
// NG: Nat <: ?T or Int ==> Nat or Int (?T = Nat)
// OK: Nat <: ?T or Int ==> ?T or Int
(sub, Type::Or(l, r))
if l.is_unbound_var()
&& !sub.is_unbound_var()
&& !r.is_unbound_var()
&& self.subtype_of(sub, r) =>
{
Ok(())
}
(sub, Type::Or(l, r))
if r.is_unbound_var()
&& !sub.is_unbound_var()
&& !l.is_unbound_var()
&& self.subtype_of(sub, l) =>
{
Ok(())
}
// e.g. Structural({ .method = (self: T) -> Int })/T
(Type::Structural(sub), Type::FreeVar(fv))
if fv.is_unbound() && sub.contains_tvar(fv) =>