Evaluator - error
Add spanless and unimplemented error variants
@@ -9,7 +9,7 @@ pub enum RuntimeErrorKind {
// Array errors
#[error("Out of bounds")]
- ArrayOutOfBounds { index : u128, bound : u128},
+ ArrayOutOfBounds { index : u128, bound : u128, span : Span},
// Environment errors
#[error("Cannot find Array")]
@@ -17,6 +17,14 @@ pub enum RuntimeErrorKind {
#[error("Unstructured Error")]
UnstructuredError { span: Span, message : String},
+
+ #[error("Spanless")]
+ // This is here due to the fact we don't have full coverage for span
+ Spanless(String),
+
+ #[error("unimplemented")]
+ Unimplemented(String),
+
#[error("Unsupported operation error")]
UnsupportedOp { span: Span, op : String, first_type : String, second_type : String},
}
@@ -44,8 +52,8 @@ impl RuntimeErrorKind {
impl DiagnosableError for RuntimeError {
fn to_diagnostic(&self) -> Diagnostic{
match &self.kind {
- RuntimeErrorKind::ArrayOutOfBounds{index, bound} => {
- Diagnostic::simple_error(format!("index out of bounds"), format!("out of bounds error, index is {} but length is {}",index, bound), Span::default())
+ RuntimeErrorKind::ArrayOutOfBounds{index, bound, span} => {
+ Diagnostic::simple_error(format!("index out of bounds"), format!("out of bounds error, index is {} but length is {}",index, bound), *span)
},
RuntimeErrorKind::ArrayNotFound{found_type, name} => {
Diagnostic::simple_error(format!("cannot find an array with name {}", name), format!("{} has type", found_type), Span::default())
@@ -56,6 +64,12 @@ impl DiagnosableError for RuntimeError {
RuntimeErrorKind::UnsupportedOp {span, op, first_type, second_type} => {
Diagnostic::simple_error("unsupported operation".to_owned(), format!("no support for {} with types {} and {}", op, first_type, second_type), *span)
},
+ RuntimeErrorKind::Spanless(message) => {
+ Diagnostic::from_message(&message)
+ }
+ RuntimeErrorKind::Unimplemented(message) => {
+ Diagnostic::from_message(&message)
+ }
}
}
}
\ No newline at end of file
