diff --git a/src/wasm-lib/kcl/src/std/array.rs b/src/wasm-lib/kcl/src/std/array.rs index 925a7efb89..5ecc658587 100644 --- a/src/wasm-lib/kcl/src/std/array.rs +++ b/src/wasm-lib/kcl/src/std/array.rs @@ -28,6 +28,18 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result Ok(user_val.value), + _ => Err(()), + }) + .collect::, _>>(); + if let Ok(unwrapped) = unwrapped { + let uv = UserVal::new(vec![args.source_range.into()], unwrapped); + return Ok(KclValue::UserVal(uv)); + } let uv = UserVal::new(vec![args.source_range.into()], new_array); Ok(KclValue::UserVal(uv)) } diff --git a/src/wasm-lib/tests/executor/inputs/no_visuals/double_map.kcl b/src/wasm-lib/tests/executor/inputs/no_visuals/double_map.kcl new file mode 100644 index 0000000000..93f9d77113 --- /dev/null +++ b/src/wasm-lib/tests/executor/inputs/no_visuals/double_map.kcl @@ -0,0 +1,6 @@ +fn increment = (i) => { return i + 1 } + +xs = [0..2] +ys = xs +|> map(%, increment) +|> map(%, increment) diff --git a/src/wasm-lib/tests/executor/no_visuals.rs b/src/wasm-lib/tests/executor/no_visuals.rs index 37d0ef1ba2..c5e2cb0ab1 100644 --- a/src/wasm-lib/tests/executor/no_visuals.rs +++ b/src/wasm-lib/tests/executor/no_visuals.rs @@ -28,7 +28,15 @@ macro_rules! gen_test_fail { async fn run(code: &str) { let (ctx, program, id_generator) = setup(code).await; - ctx.run(&program, None, id_generator).await.unwrap(); + let res = ctx.run(&program, None, id_generator).await; + match res { + Ok(state) => { + println!("{:#?}", state.memory); + } + Err(e) => { + panic!("{e}"); + } + } } async fn setup(program: &str) -> (ExecutorContext, Program, IdGenerator) { @@ -102,3 +110,4 @@ gen_test!(if_else); // ); gen_test_fail!(comparisons_multiple, "syntax: Invalid number: true"); gen_test!(add_lots); +gen_test!(double_map);