fix: sub unification bug

This commit is contained in:
Shunsuke Shibayama 2024-02-16 17:50:57 +09:00
parent fae18d3c15
commit 5f652f3dd5
2 changed files with 14 additions and 2 deletions

View file

@ -1544,7 +1544,9 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
Ok(())
}
// TODO: Current implementation is inefficient because coercion is performed twice with `subtype_of` in `sub_unify`
/// e.g. `maybe_sub: Vec, maybe_sup: Iterable T (Vec <: Iterable Int, T <: Int)`
///
/// TODO: Current implementation is inefficient because coercion is performed twice with `subtype_of` in `sub_unify`
fn nominal_sub_unify(
&self,
maybe_sub: &Type,
@ -1573,7 +1575,9 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
compatibles.push(&sub_ctx.typ);
}
for sup_ty in sups {
if self.ctx.subtype_of(sup_ty, maybe_sup) {
if sup_ty.qual_name() == maybe_sup.qual_name()
&& self.ctx.subtype_of(sup_ty, maybe_sup)
{
if !compatibles.is_empty() {
let mut idx = compatibles.len();
for (i, comp) in compatibles.iter().enumerate() {