From a4cabc1ac71f9a3ff2b1c44a68535738c231ffeb Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 8 Jun 2020 14:10:06 +0800 Subject: [PATCH] Better String parameter error message. --- src/engine.rs | 6 +++++- tests/decrement.rs | 2 +- tests/string.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index 9be3c04c..4ad31b36 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -708,7 +708,11 @@ impl Engine { "{} ({})", fn_name, args.iter() - .map(|name| self.map_type_name(name.type_name())) + .map(|name| if name.is::() { + "&str | ImmutableString" + } else { + self.map_type_name(name.type_name()) + }) .collect::>() .join(", ") ), diff --git a/tests/decrement.rs b/tests/decrement.rs index ab1f9376..1b74dfe9 100644 --- a/tests/decrement.rs +++ b/tests/decrement.rs @@ -8,7 +8,7 @@ fn test_decrement() -> Result<(), Box> { assert!(matches!( *engine.eval::(r#"let s = "test"; s -= "ing"; s"#).expect_err("expects error"), - EvalAltResult::ErrorFunctionNotFound(err, _) if err == "- (string, string)" + EvalAltResult::ErrorFunctionNotFound(err, _) if err == "- (&str | ImmutableString, &str | ImmutableString)" )); Ok(()) diff --git a/tests/string.rs b/tests/string.rs index 27854629..6eed9e6a 100644 --- a/tests/string.rs +++ b/tests/string.rs @@ -168,7 +168,7 @@ fn test_string_fn() -> Result<(), Box> { assert!(matches!( *engine.eval::(r#"foo3("hello")"#).expect_err("should error"), - EvalAltResult::ErrorFunctionNotFound(ref x, _) if x == "foo3 (string)" + EvalAltResult::ErrorFunctionNotFound(err, _) if err == "foo3 (&str | ImmutableString)" )); Ok(())