better debug info for a mismatch

This commit is contained in:
Folkert 2021-08-20 22:41:43 +02:00
parent 19d56fa7d4
commit aa042f3357
2 changed files with 18 additions and 2 deletions

View file

@ -327,6 +327,14 @@ fn subs_fmt_desc(this: &Descriptor, subs: &Subs, f: &mut fmt::Formatter) -> fmt:
write!(f, " m: {:?}", &this.mark) write!(f, " m: {:?}", &this.mark)
} }
pub struct SubsFmtContent<'a>(pub &'a Content, pub &'a Subs);
impl<'a> fmt::Debug for SubsFmtContent<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
subs_fmt_content(self.0, self.1, f)
}
}
fn subs_fmt_content(this: &Content, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result { fn subs_fmt_content(this: &Content, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result {
match this { match this {
Content::FlexVar(name) => write!(f, "Flex({:?})", name), Content::FlexVar(name) => write!(f, "Flex({:?})", name),
@ -345,6 +353,14 @@ fn subs_fmt_content(this: &Content, subs: &Subs, f: &mut fmt::Formatter) -> fmt:
} }
} }
pub struct SubsFmtFlatType<'a>(pub &'a FlatType, pub &'a Subs);
impl<'a> fmt::Debug for SubsFmtFlatType<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
subs_fmt_flat_type(self.0, self.1, f)
}
}
fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result { fn subs_fmt_flat_type(this: &FlatType, subs: &Subs, f: &mut fmt::Formatter) -> fmt::Result {
match this { match this {
FlatType::Apply(name, arguments) => { FlatType::Apply(name, arguments) => {

View file

@ -1076,8 +1076,8 @@ fn unify_flat_type(
// any other combination is a mismatch // any other combination is a mismatch
mismatch!( mismatch!(
"Trying to unify two flat types that are incompatible: {:?} ~ {:?}", "Trying to unify two flat types that are incompatible: {:?} ~ {:?}",
other1, roc_types::subs::SubsFmtFlatType(other1, subs),
other2 roc_types::subs::SubsFmtFlatType(other2, subs)
) )
} }
} }