From d515b1658ad75f539c103299aaac968de96dc531 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 24 Feb 2019 16:24:45 -0800 Subject: [PATCH] Some fixes --- schala-lang/language/src/typechecking.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 266dce1..09e3a24 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -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 } }