From b33e1fc80bb0e7191c1ea3378569ed8c0fe4af6d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 11 Nov 2019 18:20:52 +0000 Subject: Add more detail to TypeMismatch error --- dhall/src/error/mod.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'dhall/src/error/mod.rs') diff --git a/dhall/src/error/mod.rs b/dhall/src/error/mod.rs index 4d59cbb..e4baea0 100644 --- a/dhall/src/error/mod.rs +++ b/dhall/src/error/mod.rs @@ -111,9 +111,20 @@ impl std::fmt::Display for TypeError { 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"), + TypeMismatch(x, y, z) => { + x.span() + .error("Type error: Wrong type of function argument") + + "\n" + + &z.span().error(format!( + "This argument has type {:?}", + z.get_type().unwrap() + )) + + "\n" + + &y.span().error(format!( + "But the function expected an argument of type {:?}", + y + )) + } _ => "Type error: Unhandled error".to_string(), }; write!(f, "{}", msg) -- cgit v1.2.3