From a8c968584e2d19587c48e8c9099c8d8f7ffffba3 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Sun, 18 Dec 2022 14:56:55 -0800 Subject: [PATCH] Fix incorrect output string from try_to_type (#3351) * Minor fix of try_to_type * Add test --- arrow-ord/src/comparison.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arrow-ord/src/comparison.rs b/arrow-ord/src/comparison.rs index 196590008248..80c8b6b1c393 100644 --- a/arrow-ord/src/comparison.rs +++ b/arrow-ord/src/comparison.rs @@ -460,7 +460,7 @@ fn try_to_type_result( /// Type of expression is `Result<.., ArrowError>` macro_rules! try_to_type { ($RIGHT: expr, $TY: ident) => { - try_to_type_result($RIGHT.$TY(), stringify!($RIGHT), stringify!($TYPE)) + try_to_type_result($RIGHT.$TY(), &format!("{:?}", $RIGHT), stringify!($TY)) }; } @@ -5827,4 +5827,22 @@ mod tests { let r = gt_eq_dyn(&a, &b).unwrap(); assert_eq!(e, r); } + + #[derive(Debug)] + struct ToType {} + + impl ToType { + fn to_i128(&self) -> Option { + None + } + } + + #[test] + fn test_try_to_type() { + let a = ToType {}; + let to_type = try_to_type!(a, to_i128).unwrap_err(); + assert!(to_type + .to_string() + .contains("Could not convert ToType with to_i128")); + } }