From 51cf8a4824f01781332c062c33f1926d2a03fcae Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 26 Feb 2018 18:23:10 -0800 Subject: [PATCH] Handle variable lookups --- src/schala_lang/typechecking.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/schala_lang/typechecking.rs b/src/schala_lang/typechecking.rs index 60b227a..ed0a8ac 100644 --- a/src/schala_lang/typechecking.rs +++ b/src/schala_lang/typechecking.rs @@ -107,7 +107,7 @@ impl TypeContext { self.unify(t2, rhs_ty)?; Ok(t3) }, - other => return Err(format!("{:?} is not a binary function type", other)) + other => Err(format!("{:?} is not a binary function type", other)) } }, &PrefixExp(ref op, ref expr) => match op.get_type()? { @@ -116,12 +116,16 @@ impl TypeContext { self.unify(t1, expr_ty)?; Ok(t2) }, - other => return Err(format!("{:?} is not a prefix op function type", other)) + other => Err(format!("{:?} is not a prefix op function type", other)) + }, + &Value(ref name) => { + match self.bindings.get(name) { + Some(ty) => Ok(ty.clone()), + None => Err(format!("No binding found for variable: {}", name)), + } }, /* - PrefixExp(Operation, Box), TupleLiteral(Vec), - Value(Rc, Vec<(Rc, Expression)>), Call { f: Box, arguments: Vec,