summaryrefslogtreecommitdiff
path: root/dhall/src/error/mod.rs
diff options
context:
space:
mode:
authorNadrieril2019-11-11 10:33:45 +0000
committerNadrieril2019-11-11 13:50:36 +0000
commit539ab468dfeca7a7b863d5166b2516a2573c044e (patch)
treed3449a5f556e0eddd02c923257bd678aa0e4f6bb /dhall/src/error/mod.rs
parent70263bb4535c40ffa73548e3f0b4b574a856d764 (diff)
Implement basicest Display for TypeError
Diffstat (limited to '')
-rw-r--r--dhall/src/error/mod.rs61
1 files changed, 18 insertions, 43 deletions
diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs
index 6d4e120..5338e2d 100644
--- a/dhall/src/error/mod.rs
+++ b/dhall/src/error/mod.rs
@@ -41,7 +41,7 @@ pub enum EncodeError {
/// A structured type error that includes context
#[derive(Debug)]
pub struct TypeError {
- type_message: TypeMessage,
+ message: TypeMessage,
context: TypecheckContext,
}
@@ -90,58 +90,33 @@ pub(crate) enum TypeMessage {
impl TypeError {
pub(crate) fn new(
context: &TypecheckContext,
- type_message: TypeMessage,
+ message: TypeMessage,
) -> Self {
TypeError {
context: context.clone(),
- type_message,
+ message,
}
}
}
-impl std::error::Error for TypeMessage {
- fn description(&self) -> &str {
+impl std::fmt::Display for TypeError {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use TypeMessage::*;
- match *self {
- // UnboundVariable => "Unbound variable",
- InvalidInputType(_) => "Invalid function input",
- InvalidOutputType(_) => "Invalid function output",
- NotAFunction(_) => "Not a function",
- TypeMismatch(_, _, _) => "Wrong type of function argument",
- _ => "Unhandled error",
- }
+ let msg = match self.message {
+ UnboundVariable(_) => "Unbound variable".to_string(),
+ InvalidInputType(_) => "Invalid function input".to_string(),
+ InvalidOutputType(_) => "Invalid function output".to_string(),
+ NotAFunction(_) => "Not a function".to_string(),
+ TypeMismatch(_, _, _) => {
+ "Wrong type of function argument".to_string()
+ }
+ _ => "Unhandled error".to_string(),
+ };
+ write!(f, "{}", msg)
}
}
-impl std::fmt::Display for TypeMessage {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- match self {
- // UnboundVariable(_) => {
- // f.write_str(include_str!("errors/UnboundVariable.txt"))
- // }
- // TypeMismatch(e0, e1, e2) => {
- // let template = include_str!("errors/TypeMismatch.txt");
- // let s = template
- // .replace("$txt0", &format!("{}", e0.as_expr()))
- // .replace("$txt1", &format!("{}", e1.as_expr()))
- // .replace("$txt2", &format!("{}", e2.as_expr()))
- // .replace(
- // "$txt3",
- // &format!(
- // "{}",
- // e2.get_type()
- // .unwrap()
- // .as_normalized()
- // .unwrap()
- // .as_expr()
- // ),
- // );
- // f.write_str(&s)
- // }
- _ => f.write_str("Unhandled error message"),
- }
- }
-}
+impl std::error::Error for TypeError {}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -151,7 +126,7 @@ impl std::fmt::Display for Error {
Error::Decode(err) => write!(f, "{:?}", err),
Error::Encode(err) => write!(f, "{:?}", err),
Error::Resolve(err) => write!(f, "{:?}", err),
- Error::Typecheck(err) => write!(f, "{:?}", err),
+ Error::Typecheck(err) => write!(f, "Type error: {}", err),
}
}
}