feat: 3 new error cases and more generic pretty printing
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::ast::{NamedDeBruijn, Term};
|
||||
@@ -18,4 +20,31 @@ pub enum Error {
|
||||
NonPolymorphicInstantiation(Value),
|
||||
#[error("Attempted to apply a non-function: {0:#?}")]
|
||||
NonFunctionalApplication(Value),
|
||||
#[error("Type mismatch expected '{0}' got '{1}'")]
|
||||
TypeMismatch(Type, Type),
|
||||
#[error("A builtin received a term argument when something else was expected:\n\n{}\n\nYou probably forgot to wrap the builtin with a force.", .0.to_pretty())]
|
||||
UnexpectedBuiltinTermArgument(Term<NamedDeBruijn>),
|
||||
#[error("A builtin expected a term argument, but something else was received:\n\n{}\n\nYou probably have an extra force wrapped around a builtin", .0.to_pretty())]
|
||||
BuiltinTermArgumentExpected(Term<NamedDeBruijn>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Type {
|
||||
Bool,
|
||||
Integer,
|
||||
String,
|
||||
ByteString,
|
||||
Unit,
|
||||
}
|
||||
|
||||
impl Display for Type {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Type::Bool => write!(f, "bool"),
|
||||
Type::Integer => write!(f, "integer"),
|
||||
Type::String => write!(f, "string"),
|
||||
Type::ByteString => write!(f, "bytestring"),
|
||||
Type::Unit => write!(f, "unit"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user