feat: 3 new error cases and more generic pretty printing

This commit is contained in:
rvcas
2022-07-15 23:26:57 -04:00
committed by Kasey White
parent 598c5364fe
commit f332dfeb38
10 changed files with 118 additions and 55 deletions

View File

@@ -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"),
}
}
}