From c4666b82ecb76a68f3ae121d3048b9cc622193d2 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 28 May 2018 23:39:58 -0700 Subject: [PATCH] Basics --- schala-lang/src/typechecking.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 33082e2..bdf89b1 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -63,7 +63,24 @@ impl TypeContext { Ok(Type::Const(TConst::Unit)) } fn infer_expr(&mut self, expr: &parsing::Expression) -> TypeResult { - Ok(Type::Const(TConst::Unit)) + match expr { + parsing::Expression(expr, Some(anno)) => { + self.infer_exprtype(expr) + }, + parsing::Expression(expr, None) => { + self.infer_exprtype(expr) + } + } + } + + fn infer_exprtype(&mut self, expr: &parsing::ExpressionType) -> TypeResult { + use self::TConst::*; + use parsing::ExpressionType::*; + Ok(match expr { + NatLiteral(_) => Type::Const(Nat), + StringLiteral(_) => Type::Const(StringT), + _ => Type::Const(Unit) + }) } }