diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index 7396605..e974ca6 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -142,24 +142,35 @@ impl<'a> TypeContext<'a> { } pub fn typecheck(&mut self, ast: &AST) -> Result { + let mut returned_type = Type::Const(TypeConst::Unit); for statement in ast.0.iter() { - self.typecheck_statement(statement.node()).map_err(|err| { err.msg })? + returned_type = self.typecheck_statement(statement.node()).map_err(|err| { err.msg })? } - Ok("unknown type".to_string()) + Ok(format!("{:?}", returned_type)) } - fn typecheck_statement(&mut self, statement: &Statement) -> InferResult<()> { + fn typecheck_statement(&mut self, statement: &Statement) -> InferResult { match statement { Statement::ExpressionStatement(e) => self.typecheck_expr(e.node()), Statement::Declaration(decl) => self.typecheck_decl(decl), } } - fn typecheck_decl(&mut self, decl: &Declaration) -> InferResult<()> { - Ok(()) + fn typecheck_decl(&mut self, decl: &Declaration) -> InferResult { + Ok(Type::Const(TypeConst::Unit)) } - fn typecheck_expr(&mut self, expr: &Expression) -> InferResult<()> { - Ok(()) + fn typecheck_expr(&mut self, expr: &Expression) -> InferResult { + match expr { + Expression(expr_type, Some(_anno)) => { + //TODO here + self.typecheck_expr_type(expr_type) + }, + Expression(expr_type, None) => self.typecheck_expr_type(expr_type) + } + } + + fn typecheck_expr_type(&mut self, expr: &ExpressionType) -> InferResult { + Ok(Type::Const(TypeConst::Unit)) } }