Include error vars in is_recursion_var checks

This commit is contained in:
Ayaz Hafiz 2022-11-16 10:02:05 -06:00
parent bef9b54124
commit 735685dd86
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
2 changed files with 16 additions and 2 deletions

View File

@ -2150,6 +2150,18 @@ impl Subs {
pub fn dbg(&self, var: Variable) -> impl std::fmt::Debug + '_ {
SubsFmtContent(self.get_content_without_compacting(var), self)
}
/// Is this variable involved in an error?
pub fn is_error_var(&self, var: Variable) -> bool {
match self.get_content_without_compacting(var) {
Content::Error => true,
Content::FlexVar(Some(index)) => {
// Generated names for errors start with `#`
self[*index].as_str().starts_with('#')
}
_ => false,
}
}
}
#[inline(always)]

View File

@ -2807,7 +2807,7 @@ fn unify_shared_tags_merge_new<M: MetaCollector>(
let flat_type = match recursion_var {
Rec::None => FlatType::TagUnion(new_tags, new_ext_var),
Rec::Left(rec) | Rec::Right(rec) | Rec::Both(rec, _) => {
debug_assert!(is_recursion_var(env.subs, rec));
debug_assert!(is_recursion_var(env.subs, rec), "{:?}", env.subs.dbg(rec));
FlatType::RecursiveTagUnion(rec, new_tags, new_ext_var)
}
};
@ -3494,7 +3494,9 @@ fn is_recursion_var(subs: &Subs, var: Variable) -> bool {
matches!(
subs.get_content_without_compacting(var),
Content::RecursionVar { .. }
)
) ||
// Error-like vars should always unify, so pretend they are recursion vars too.
subs.is_error_var(var)
}
#[allow(clippy::too_many_arguments)]