From 2f18529bcc9904e5b0175b6471e4c71040cb4ca1 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 10 Oct 2017 02:41:17 -0700 Subject: [PATCH] Operator typing a little bit --- src/schala_lang/type_check.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index 0a21189..7aa42f6 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -181,10 +181,23 @@ impl TypeContext { .ok_or(format!("Couldn't find {}", name))? }, (&BinExp(ref op, box ref lhs, box ref rhs), _) => { - let _f_type = self.infer_op(op); - let _lhs_type = self.infer(&lhs); - let _rhs_type = self.infer(&rhs); - unimplemented!() + let op_type = self.infer_op(op)?; + let lhs_type = self.infer(&lhs)?; + + match op_type { + TConst(FunctionT(box t1, box t2)) => { + let _ = self.unify(&t1, &lhs_type)?; + let rhs_type = self.infer(&rhs)?; + match t2 { + TConst(FunctionT(box t3, box t_ret)) => { + let _ = self.unify(&t3, &rhs_type)?; + t_ret + }, + _ => return Err(format!("Another bad type for operator")) + } + }, + _ => return Err(format!("Bad type for operator")), + } }, (&Call { ref f, ref arguments }, _) => { let f_type = self.infer(&*f)?; @@ -245,6 +258,7 @@ mod tests { #[test] fn basic_inference() { type_test!("30", TConst(Integer)); + type_test!("1 + 2", TConst(Integer)); } }