diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index e01db56..d8938c0 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -207,7 +207,6 @@ impl<'a> TypeContext<'a> { fn typecheck_expr(&mut self, expr: &Expression) -> InferResult { match expr { Expression(expr_type, Some(anno)) => { - //TODO here let t1 = self.typecheck_expr_type(expr_type)?; let t2 = self.get_type_from_name(anno)?; self.unify(t2, t1) @@ -225,6 +224,7 @@ impl<'a> TypeContext<'a> { StringLiteral(_) => Type::Const(TypeConst::StringT), PrefixExp(op, expr) => self.typecheck_prefix(op, expr.node())?, IfExpression { discriminator, body } => self.typecheck_if_expr(discriminator, body)?, + Value(val) => self.handle_value(val)?, _ => Type::Const(TypeConst::Unit) }) } @@ -250,6 +250,13 @@ impl<'a> TypeContext<'a> { Ok(Type::Const(TypeConst::Unit)) } + fn handle_value(&mut self, val: &Rc) -> InferResult { + match self.variable_map.lookup(val) { + Some(ty) => Ok(ty.clone()), + None => TypeError::new(&format!("Couldn't find variable: {}", val)) + } + } + fn unify(&mut self, t1: Type, t2: Type) -> InferResult { use self::Type::*; use self::TypeConst::*; Ok(match (t1, t2) {