Some fixes

This commit is contained in:
greg 2019-02-24 16:24:45 -08:00
parent e501f4bd10
commit d515b1658a

View File

@ -118,9 +118,9 @@ impl Type {
} else {
let mut buf = String::new();
for p in params.iter() {
write!(buf, "{} -> ", p.to_string());
write!(buf, "{} -> ", p.to_string()).unwrap();
}
write!(buf, "{}", ret.to_string());
write!(buf, "{}", ret.to_string()).unwrap();
buf
}
},
@ -417,7 +417,10 @@ impl<'a> TypeContext<'a> {
(Var(v1), Var(v2)) => {
//TODO add occurs check
self.unification_table.unify_var_var(v1.clone(), v2.clone())
.or_else(|_| TypeError::new(format!("Two type variables {:?} and {:?} couldn't unify", v1, v2)))?;
.or_else(|e| {
println!("Unify error: {:?}", e);
TypeError::new(format!("Two type variables {:?} and {:?} couldn't unify", v1, v2))
})?;
Ok(Var(v1.clone())) //arbitrary decision I think
},
(a, b) => TypeError::new(format!("{:?} and {:?} do not unify", a, b)),
@ -425,9 +428,8 @@ impl<'a> TypeContext<'a> {
}
fn fresh_type_variable(&mut self) -> TypeVar {
let n = self.type_var_count;
self.type_var_count += 1;
TypeVar(n)
let new_type_var = self.unification_table.new_key(None);
new_type_var
}
}