Skip to content

Commit

Permalink
refactor: merge CompileError and CompileErrorInfo in a single type. (#82
Browse files Browse the repository at this point in the history
)
  • Loading branch information
plusvic authored Feb 19, 2024
1 parent b02e768 commit 96488cc
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 162 deletions.
35 changes: 2 additions & 33 deletions lib/src/compiler/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,16 @@ pub enum Error {
ParseError(#[from] ParseError),

#[error(transparent)]
CompileError(#[from] CompileError),
CompileError(#[from] Box<CompileError>),

#[error(transparent)]
VariableError(#[from] VariableError),
}

/// Error produced while compiling rules.
#[derive(Eq, PartialEq)]
pub struct CompileError(Box<CompileErrorInfo>);

impl CompileError {
/// Returns additional information about the error.
pub fn info(&self) -> &CompileErrorInfo {
self.0.as_ref()
}
}

impl Debug for CompileError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.0)
}
}

impl Display for CompileError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

impl From<CompileErrorInfo> for CompileError {
fn from(value: CompileErrorInfo) -> Self {
Self(Box::new(value))
}
}

impl std::error::Error for CompileError {}

/// An error occurred during the compilation process.
#[derive(DeriveError, Eq, PartialEq)]
#[non_exhaustive]
pub enum CompileErrorInfo {
pub enum CompileError {
#[error("wrong type")]
#[label(
"expression should be {expected_types}, but is `{actual_type}`",
Expand Down
Loading

0 comments on commit 96488cc

Please sign in to comment.