fix error range kcl embedded function and add test (#1691)
* updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * new images Signed-off-by: Jess Frazelle <github@jessfraz.com> * new images Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
@ -1128,7 +1128,14 @@ impl CallExpression {
|
|||||||
|
|
||||||
// Call the stdlib function
|
// Call the stdlib function
|
||||||
let p = func.function().clone().body;
|
let p = func.function().clone().body;
|
||||||
let results = crate::executor::execute(p, &mut fn_memory, BodyType::Block, ctx).await?;
|
let results = match crate::executor::execute(p, &mut fn_memory, BodyType::Block, ctx).await {
|
||||||
|
Ok(results) => results,
|
||||||
|
Err(err) => {
|
||||||
|
// We need to override the source ranges so we don't get the embedded kcl
|
||||||
|
// function from the stdlib.
|
||||||
|
return Err(err.override_source_ranges(vec![self.into()]));
|
||||||
|
}
|
||||||
|
};
|
||||||
let out = results.return_;
|
let out = results.return_;
|
||||||
let result = out.ok_or_else(|| {
|
let result = out.ok_or_else(|| {
|
||||||
KclError::UndefinedValue(KclErrorDetails {
|
KclError::UndefinedValue(KclErrorDetails {
|
||||||
|
@ -123,6 +123,25 @@ impl KclError {
|
|||||||
data: None,
|
data: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn override_source_ranges(&self, source_ranges: Vec<SourceRange>) -> Self {
|
||||||
|
let mut new = self.clone();
|
||||||
|
match &mut new {
|
||||||
|
KclError::Lexical(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::Syntax(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::Semantic(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::Type(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::Unimplemented(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::Unexpected(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::ValueAlreadyDefined(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::UndefinedValue(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::InvalidExpression(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::Engine(e) => e.source_ranges = source_ranges,
|
||||||
|
KclError::Internal(e) => e.source_ranges = source_ranges,
|
||||||
|
}
|
||||||
|
|
||||||
|
new
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is different than to_string() in that it will serialize the Error
|
/// This is different than to_string() in that it will serialize the Error
|
||||||
|
@ -1316,3 +1316,58 @@ const part002 = startSketchOn(part001, "end")
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
twenty_twenty::assert_image("tests/executor/outputs/sketch_on_face_circle_tagged.png", &result, 1.0);
|
twenty_twenty::assert_image("tests/executor/outputs/sketch_on_face_circle_tagged.png", &result, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn serial_test_stdlib_kcl_error_circle() {
|
||||||
|
let code = r#"// Mounting Plate
|
||||||
|
// A flat piece of material, often metal or plastic, that serves as a support or base for attaching, securing, or mounting various types of equipment, devices, or components.
|
||||||
|
|
||||||
|
// Create a function that defines the body width and length of the mounting plate. Tag the corners so they can be passed through the fillet function.
|
||||||
|
fn rectShape = (pos, w, l) => {
|
||||||
|
const rr = startSketchOn('XY')
|
||||||
|
|> startProfileAt([pos[0] - (w / 2), pos[1] - (l / 2)], %)
|
||||||
|
|> lineTo({
|
||||||
|
to: [pos[0] + w / 2, pos[1] - (l / 2)],
|
||||||
|
tag: "edge1"
|
||||||
|
}, %)
|
||||||
|
|> lineTo({
|
||||||
|
to: [pos[0] + w / 2, pos[1] + l / 2],
|
||||||
|
tag: "edge2"
|
||||||
|
}, %)
|
||||||
|
|> lineTo({
|
||||||
|
to: [pos[0] - (w / 2), pos[1] + l / 2],
|
||||||
|
tag: "edge3"
|
||||||
|
}, %)
|
||||||
|
|> close(%, "edge4")
|
||||||
|
return rr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the hole radius and x, y location constants
|
||||||
|
const holeRadius = 1
|
||||||
|
const holeIndex = 6
|
||||||
|
|
||||||
|
// Create the mounting plate extrusion, holes, and fillets
|
||||||
|
const part = rectShape([0, 0], 20, 20)
|
||||||
|
|> hole(circle('XY', [-holeIndex, holeIndex], holeRadius), %)
|
||||||
|
|> hole(circle('XY', [holeIndex, holeIndex], holeRadius), %)
|
||||||
|
|> hole(circle('XY', [-holeIndex, -holeIndex], holeRadius), %)
|
||||||
|
|> hole(circle('XY', [holeIndex, -holeIndex], holeRadius), %)
|
||||||
|
|> extrude(2, %)
|
||||||
|
|> fillet({
|
||||||
|
radius: 4,
|
||||||
|
tags: [
|
||||||
|
getNextAdjacentEdge("edge1", %),
|
||||||
|
getNextAdjacentEdge("edge2", %),
|
||||||
|
getNextAdjacentEdge("edge3", %),
|
||||||
|
getNextAdjacentEdge("edge4", %)
|
||||||
|
]
|
||||||
|
}, %)
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let result = execute_and_snapshot(code, kittycad::types::UnitLength::Mm).await;
|
||||||
|
assert!(result.is_err());
|
||||||
|
assert_eq!(
|
||||||
|
result.err().unwrap().to_string(),
|
||||||
|
r#"semantic: KclErrorDetails { source_ranges: [SourceRange([987, 1036])], message: "MemberExpression array is not an array: UserVal(UserVal { value: String(\"XY\"), meta: [Metadata { source_range: SourceRange([994, 998]) }] })" }"#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 131 KiB After Width: | Height: | Size: 131 KiB |
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 99 KiB |
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 102 KiB |
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 111 KiB |
Before Width: | Height: | Size: 127 KiB After Width: | Height: | Size: 126 KiB |