diff --git a/schala-lang/language/src/symbol_table/mod.rs b/schala-lang/language/src/symbol_table/mod.rs index 65ea33a..8c77f6a 100644 --- a/schala-lang/language/src/symbol_table/mod.rs +++ b/schala-lang/language/src/symbol_table/mod.rs @@ -134,7 +134,10 @@ impl SymbolTable { /// compilation process. pub fn process_ast(&mut self, ast: &ast::AST) -> Result<(), String> { - self.populate_name_tables(ast)?; + let errs = self.populate_name_tables(ast); + if !errs.is_empty() { + return Err(format!("{:?}", errs)); + } self.resolve_symbol_ids(ast)?; Ok(()) } @@ -211,14 +214,12 @@ impl SymbolTable { /// constants, functions, types, and modules defined within. This simultaneously /// checks for dupicate definitions (and returns errors if discovered), and sets /// up name tables that will be used by further parts of the compiler - fn populate_name_tables(&mut self, ast: &ast::AST) -> Result<(), String> { + fn populate_name_tables(&mut self, ast: &ast::AST) -> Vec { let mut scope_stack = vec![]; self.add_from_scope(ast.statements.as_ref(), &mut scope_stack) - .map_err(|err| format!("{:?}", err))?; - Ok(()) } - fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec) -> Result<(), Vec> { + fn add_from_scope<'a>(&'a mut self, statements: &[Statement], scope_stack: &mut Vec) -> Vec { let mut errors = vec![]; for statement in statements { @@ -245,19 +246,12 @@ impl SymbolTable { StatementKind::Declaration(Declaration::TypeDecl { name, body, mutable }) => { self.add_type_members(name, body, mutable, location, scope_stack) } - _ => Ok(()) + _ => vec![] }; - - if let Err(errs) = recursive_errs { - errors.extend(errs.into_iter()); - } + errors.extend(recursive_errs.into_iter()); } - if errors.is_empty() { - Ok(()) - } else { - Err(errors) - } + errors } fn add_single_statement(&mut self, kind: &StatementKind, location: Location, scope_stack: &Vec) -> Result<(), DuplicateName> { @@ -304,7 +298,7 @@ impl SymbolTable { Ok(()) } - fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec) -> Result<(), Vec> { + fn add_type_members(&mut self, type_name: &TypeSingletonName, type_body: &TypeBody, _mutable: &bool, location: Location, scope_stack: &mut Vec) -> Vec { let mut errors = vec![]; let mut register = |fqsn: FQSN, spec: SymbolSpec| { @@ -378,11 +372,6 @@ impl SymbolTable { } scope_stack.pop(); - - if errors.is_empty() { - Ok(()) - } else { - Err(errors) - } + errors } }