From c9c248a4cab21fa1ae7692cd193e3b2c698d431d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 11 Nov 2019 13:49:47 +0000 Subject: Add a few more pretty errors --- dhall/src/core/value.rs | 3 +++ dhall/src/error/mod.rs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'dhall/src') diff --git a/dhall/src/core/value.rs b/dhall/src/core/value.rs index 61c7015..d4f5131 100644 --- a/dhall/src/core/value.rs +++ b/dhall/src/core/value.rs @@ -165,6 +165,9 @@ impl Value { _ => None, } } + pub(crate) fn span(&self) -> Span { + self.as_internal().span.clone() + } fn as_internal(&self) -> Ref { self.0.borrow() diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs index 02e8ed3..4d59cbb 100644 --- a/dhall/src/error/mod.rs +++ b/dhall/src/error/mod.rs @@ -104,16 +104,16 @@ impl std::fmt::Display for TypeError { use TypeMessage::*; let msg = match &self.message { UnboundVariable(span) => span.error("Type error: Unbound variable"), - InvalidInputType(_) => { - "Type error: Invalid function input".to_string() + InvalidInputType(v) => { + v.span().error("Type error: Invalid function input") } - InvalidOutputType(_) => { - "Type error: Invalid function output".to_string() - } - NotAFunction(_) => "Type error: Not a function".to_string(), - TypeMismatch(_, _, _) => { - "Type error: Wrong type of function argument".to_string() + InvalidOutputType(v) => { + v.span().error("Type error: Invalid function output") } + NotAFunction(v) => v.span().error("Type error: Not a function"), + TypeMismatch(v, _, _) => v + .span() + .error("Type error: Wrong type of function argument"), _ => "Type error: Unhandled error".to_string(), }; write!(f, "{}", msg) -- cgit v1.2.3