From 47cbd29c27e05039f1a60778f70ae7d2cb9664dd Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 1 Aug 2023 09:43:47 -0700 Subject: [PATCH] Added detailed conversion error --- src/evaluate/mod.rs | 6 +++++- src/evaluate/operator.rs | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/evaluate/mod.rs b/src/evaluate/mod.rs index 657d9b2..d9078b6 100644 --- a/src/evaluate/mod.rs +++ b/src/evaluate/mod.rs @@ -10,6 +10,7 @@ pub enum EvalError { TooBig, ZeroDivision, IncompatibleUnit, + IncompatibleUnits(String, String), BadDefineName, Undefined(String) } @@ -28,7 +29,10 @@ impl ToString for EvalError { String::from("Division by zero") }, EvalError::IncompatibleUnit => { - String::from("Incompatible units") + String::from("Incompatible unit") + }, + EvalError::IncompatibleUnits(a, b) => { + format!("Incompatible units ({} and {})", a, b) }, EvalError::BadDefineName => { String::from("Invalid variable name") diff --git a/src/evaluate/operator.rs b/src/evaluate/operator.rs index 2b0798c..270c3c3 100644 --- a/src/evaluate/operator.rs +++ b/src/evaluate/operator.rs @@ -157,7 +157,13 @@ pub fn eval_operator(g: &Expression, context: &mut Context) -> Result