Skip to content

Commit

Permalink
chore: continue checking even if AST-linking failed
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Sep 18, 2024
1 parent ae039c9 commit 43828f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions crates/erg_compiler/link_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -31,7 +31,7 @@ impl ASTLinker {
}
}

pub fn link(mut self, ast: AST, mode: &str) -> Result<AST, TyCheckErrors> {
pub fn link(mut self, ast: AST, mode: &str) -> Failable<AST> {
log!(info "the AST-linking process has started.");
let mut new = vec![];
for chunk in ast.module.into_iter() {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl ASTLinker {
if self.errs.is_empty() {
Ok(ast)
} else {
Err(self.errs)
Err((ast, self.errs))
}
}

Expand Down
12 changes: 7 additions & 5 deletions crates/erg_compiler/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3770,11 +3770,13 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
pub fn lower(&mut self, ast: AST, mode: &str) -> Result<CompleteArtifact, IncompleteArtifact> {
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() {
Expand Down

0 comments on commit 43828f6

Please sign in to comment.