diff --git a/src/wasm-lib/kcl/src/executor.rs b/src/wasm-lib/kcl/src/executor.rs index 4c4666fad..5d4e43ef4 100644 --- a/src/wasm-lib/kcl/src/executor.rs +++ b/src/wasm-lib/kcl/src/executor.rs @@ -620,6 +620,22 @@ pub async fn execute( let result = call_expr.execute(memory, &mut pipe_info, engine).await?; args.push(result); } + Value::BinaryExpression(binary_expression) => { + let result = binary_expression.get_result(memory, &mut pipe_info, engine).await?; + args.push(result); + } + Value::UnaryExpression(unary_expression) => { + let result = unary_expression.get_result(memory, &mut pipe_info, engine).await?; + args.push(result); + } + Value::ObjectExpression(object_expression) => { + let result = object_expression.execute(memory, &mut pipe_info, engine).await?; + args.push(result); + } + Value::ArrayExpression(array_expression) => { + let result = array_expression.execute(memory, &mut pipe_info, engine).await?; + args.push(result); + } // We do nothing for the rest. _ => (), } @@ -679,7 +695,7 @@ pub async fn execute( message: format!( "Expected {} arguments, got {}", function_expression.params.len(), - args.len() + args.len(), ), source_ranges: vec![(&function_expression).into()], })); diff --git a/src/wasm-lib/kcl/src/parser.rs b/src/wasm-lib/kcl/src/parser.rs index 88aa96887..274bce9e5 100644 --- a/src/wasm-lib/kcl/src/parser.rs +++ b/src/wasm-lib/kcl/src/parser.rs @@ -3484,7 +3484,6 @@ let other_thing = 2 * cos(3)"#; } #[test] - #[ignore] // ignore until more stack fixes fn test_parse_pipes_on_pipes() { let code = include_str!("../../tests/executor/inputs/pipes_on_pipes.kcl"); @@ -3492,4 +3491,23 @@ let other_thing = 2 * cos(3)"#; let parser = Parser::new(tokens); parser.ast().unwrap(); } + + #[test] + fn test_negative_arguments() { + let some_program_string = r#"fn box = (p, h, l, w) => { + const myBox = startSketchAt(p) + |> line([0, l], %) + |> line([w, 0], %) + |> line([0, -l], %) + |> close(%) + |> extrude(h, %) + + return myBox +} +let myBox = box([0,0], -3, -16, -10) +show(myBox)"#; + let tokens = crate::token::lexer(some_program_string); + let parser = Parser::new(tokens); + parser.ast().unwrap(); + } } diff --git a/src/wasm-lib/tests/executor/main.rs b/src/wasm-lib/tests/executor/main.rs index a92521b07..2781f03ed 100644 --- a/src/wasm-lib/tests/executor/main.rs +++ b/src/wasm-lib/tests/executor/main.rs @@ -227,3 +227,28 @@ show(body)"#; let result = execute_and_snapshot(code).await.unwrap(); twenty_twenty::assert_image("tests/executor/outputs/close_arc.png", &result, 1.0); } + +#[tokio::test(flavor = "multi_thread")] +async fn test_negative_args() { + let code = r#"const width = 5 +const height = 10 +const length = 12 + +fn box = (sk1, sk2, scale) => { + const boxSketch = startSketchAt([sk1, sk2]) + |> line([0, scale], %) + |> line([scale, 0], %) + |> line([0, -scale], %) + |> close(%) + |> extrude(scale, %) + return boxSketch +} + +box(0, 0, 5) +box(10, 23, 8) +let thing = box(-12, -15, 10) +box(-20, -5, 10)"#; + + let result = execute_and_snapshot(code).await.unwrap(); + twenty_twenty::assert_image("tests/executor/outputs/negative_args.png", &result, 1.0); +} diff --git a/src/wasm-lib/tests/executor/outputs/negative_args.png b/src/wasm-lib/tests/executor/outputs/negative_args.png new file mode 100644 index 000000000..73c2a53d1 Binary files /dev/null and b/src/wasm-lib/tests/executor/outputs/negative_args.png differ