fix cryptic error (#3234)
* fix cryptic error Signed-off-by: Jess Frazelle <github@jessfraz.com> * Update types.rs --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -1494,9 +1494,14 @@ impl CallExpression {
|
||||
})?;
|
||||
|
||||
let result = result.ok_or_else(|| {
|
||||
let mut source_ranges: Vec<SourceRange> = vec![self.into()];
|
||||
// We want to send the source range of the original function.
|
||||
if let MemoryItem::Function { meta, .. } = func {
|
||||
source_ranges = meta.iter().map(|m| m.source_range).collect();
|
||||
};
|
||||
KclError::UndefinedValue(KclErrorDetails {
|
||||
message: format!("Result of user-defined function {} is undefined", fn_name),
|
||||
source_ranges: vec![self.into()],
|
||||
source_ranges,
|
||||
})
|
||||
})?;
|
||||
let result = result.get_value()?;
|
||||
|
||||
@ -2735,6 +2735,22 @@ const bracket = startSketchOn('XY')
|
||||
parse_execute(ast).await.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_execute_function_no_return() {
|
||||
let ast = r#"fn test = (origin) => {
|
||||
origin
|
||||
}
|
||||
|
||||
test([0, 0])
|
||||
"#;
|
||||
let result = parse_execute(ast).await;
|
||||
assert!(result.is_err());
|
||||
assert_eq!(
|
||||
result.unwrap_err().to_string(),
|
||||
r#"undefined value: KclErrorDetails { source_ranges: [SourceRange([10, 34])], message: "Result of user-defined function test is undefined" }"#.to_owned()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn test_math_doubly_nested_parens() {
|
||||
let ast = r#"const sigmaAllow = 35000 // psi
|
||||
|
||||
Reference in New Issue
Block a user