diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 07d113a..1990485 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -45,7 +45,6 @@ pub enum Type { #[derive(Debug, PartialEq, Clone)] pub struct TVar(String); - #[derive(Debug, PartialEq, Clone)] pub enum TConst { Unit, @@ -186,17 +185,23 @@ impl TypeContext { } output } + + pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult { + let ref block = ast.0; + Ok(self.type_check_block(block)?) + } } impl TypeContext { - pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult { - use self::Type::*; use self::TConst::*; - let mut ret_type = Const(Unit); - for statement in ast.0.iter() { + + fn type_check_block(&mut self, statements: &Vec) -> TypeResult { + let mut ret_type = Type::Const(TConst::Unit); + for statement in statements { ret_type = self.type_check_statement(statement)?; } Ok(ret_type) } + fn type_check_statement(&mut self, statement: &parsing::Statement) -> TypeResult { use self::parsing::Statement::*; match statement {