From 43828f6bb8e6463b158f03aebc95c2b0a359eeea Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Wed, 18 Sep 2024 14:30:10 +0900 Subject: [PATCH] chore: continue checking even if AST-linking failed --- crates/erg_compiler/link_ast.rs | 6 +++--- crates/erg_compiler/lower.rs | 12 +++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/erg_compiler/link_ast.rs b/crates/erg_compiler/link_ast.rs index 7eb1045d7..0d35e2f0b 100644 --- a/crates/erg_compiler/link_ast.rs +++ b/crates/erg_compiler/link_ast.rs @@ -9,7 +9,7 @@ use erg_parser::ast::{ TypeSpec, AST, }; -use crate::error::{TyCheckError, TyCheckErrors}; +use crate::error::{Failable, TyCheckError, TyCheckErrors}; /// Combine method definitions across multiple modules, specialized class contexts, etc. #[derive(Debug, Default)] @@ -31,7 +31,7 @@ impl ASTLinker { } } - pub fn link(mut self, ast: AST, mode: &str) -> Result { + pub fn link(mut self, ast: AST, mode: &str) -> Failable { log!(info "the AST-linking process has started."); let mut new = vec![]; for chunk in ast.module.into_iter() { @@ -111,7 +111,7 @@ impl ASTLinker { if self.errs.is_empty() { Ok(ast) } else { - Err(self.errs) + Err((ast, self.errs)) } } diff --git a/crates/erg_compiler/lower.rs b/crates/erg_compiler/lower.rs index 04f45d4c7..04d161b48 100644 --- a/crates/erg_compiler/lower.rs +++ b/crates/erg_compiler/lower.rs @@ -3770,11 +3770,13 @@ impl GenericASTLowerer { pub fn lower(&mut self, ast: AST, mode: &str) -> Result { log!(info "the AST lowering process has started."); log!(info "the type-checking process has started."); - let ast = ASTLinker::new(self.cfg.clone()) - .link(ast, mode) - .map_err(|errs| { - IncompleteArtifact::new(None, errs, LowerWarnings::from(self.warns.take_all())) - })?; + let ast = match ASTLinker::new(self.cfg.clone()).link(ast, mode) { + Ok(ast) => ast, + Err((ast, errs)) => { + self.errs.extend(errs); + ast + } + }; if mode == "declare" { let hir = self.declare_module(ast); if self.errs.is_empty() {