Skip to content

Commit

Permalink
refactor: merge CompileError and CompileErrorInfo in a single type.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Feb 19, 2024
1 parent b02e768 commit 1e57f49
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 139 deletions.
33 changes: 1 addition & 32 deletions lib/src/compiler/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,10 @@ pub enum Error {
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 1e57f49

Please sign in to comment.