diff --git a/compiler/erg_compiler/builder.rs b/compiler/erg_compiler/builder.rs index 0088a6a6..4fe45964 100644 --- a/compiler/erg_compiler/builder.rs +++ b/compiler/erg_compiler/builder.rs @@ -38,10 +38,7 @@ impl HIRBuilder { let ast = Reorderer::new() .reorder(ast) .map_err(|errs| self.convert(errs))?; - let (hir, ctx) = self - .checker - .check(ast, mode) - .map_err(|errs| self.convert(errs))?; + let (hir, ctx) = self.checker.check(ast, mode)?; self.mod_cache.register(var_name, Some(hir), ctx); Ok(()) } diff --git a/compiler/erg_compiler/check.rs b/compiler/erg_compiler/check.rs index 832a870a..64613655 100644 --- a/compiler/erg_compiler/check.rs +++ b/compiler/erg_compiler/check.rs @@ -1,6 +1,6 @@ use erg_common::config::{ErgConfig, Input}; use erg_common::error::MultiErrorDisplay; -use erg_common::traits::Runnable; +use erg_common::traits::{Runnable, Stream}; use erg_common::Str; use erg_parser::ast::AST; @@ -8,7 +8,7 @@ use erg_parser::builder::ASTBuilder; use crate::context::Context; use crate::effectcheck::SideEffectChecker; -use crate::error::{TyCheckError, TyCheckErrors}; +use crate::error::{CompileError, CompileErrors, TyCheckErrors}; use crate::hir::HIR; use crate::lower::ASTLowerer; use crate::mod_cache::SharedModuleCache; @@ -22,8 +22,8 @@ pub struct Checker { } impl Runnable for Checker { - type Err = TyCheckError; - type Errs = TyCheckErrors; + type Err = CompileError; + type Errs = CompileErrors; const NAME: &'static str = "Erg type-checker"; fn new(cfg: ErgConfig) -> Self { @@ -48,7 +48,7 @@ impl Runnable for Checker { Ok(()) } - fn eval(&mut self, src: String) -> Result { + fn eval(&mut self, src: String) -> Result { let cfg = ErgConfig { input: Input::Str(src), ..self.cfg().copy() @@ -72,14 +72,30 @@ impl Checker { } } - pub fn check(&mut self, ast: AST, mode: &str) -> Result<(HIR, Context), TyCheckErrors> { - let (hir, ctx, warns) = self.lowerer.lower(ast, mode)?; + fn convert(&self, errs: TyCheckErrors) -> CompileErrors { + errs.into_iter() + .map(|e| CompileError::new(e.core, self.input().clone(), e.caused_by)) + .collect::>() + .into() + } + + pub fn check(&mut self, ast: AST, mode: &str) -> Result<(HIR, Context), CompileErrors> { + let (hir, ctx, warns) = self + .lowerer + .lower(ast, mode) + .map_err(|errs| self.convert(errs))?; if self.cfg().verbose >= 2 { + let warns = self.convert(warns); warns.fmt_all_stderr(); } let effect_checker = SideEffectChecker::new(); - let hir = effect_checker.check(hir)?; - let hir = self.ownership_checker.check(hir)?; + let hir = effect_checker + .check(hir) + .map_err(|errs| self.convert(errs))?; + let hir = self + .ownership_checker + .check(hir) + .map_err(|errs| self.convert(errs))?; Ok((hir, ctx)) } } diff --git a/compiler/erg_compiler/error.rs b/compiler/erg_compiler/error.rs index d1548614..602a0871 100644 --- a/compiler/erg_compiler/error.rs +++ b/compiler/erg_compiler/error.rs @@ -246,21 +246,6 @@ impl From for TyCheckError { } } -impl ErrorDisplay for TyCheckError { - fn core(&self) -> &ErrorCore { - &self.core - } - fn input(&self) -> &Input { - &Input::Dummy - } - fn caused_by(&self) -> &str { - &self.caused_by - } - fn ref_inner(&self) -> Option<&Self> { - None - } -} - impl TyCheckError { pub const fn new(core: ErrorCore, caused_by: AtomicStr) -> Self { Self { core, caused_by } @@ -1313,7 +1298,6 @@ passed keyword args: {RED}{kw_args_len}{RESET}" pub struct TyCheckErrors(Vec); impl_stream_for_wrapper!(TyCheckErrors, TyCheckError); -impl MultiErrorDisplay for TyCheckErrors {} impl From> for TyCheckErrors { fn from(errs: Vec) -> Self {