Skip to content

Commit

Permalink
Fix the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Oct 15, 2024
1 parent 03fe782 commit f7640e0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/wasm-lib/kcl/src/std/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ pub async fn map(exec_state: &mut ExecState, args: Args) -> Result<KclValue, Kcl
memory: *f.memory,
};
let new_array = inner_map(array, map_fn, exec_state, &args).await?;
let unwrapped = new_array
.clone()
.into_iter()
.map(|k| match k {
KclValue::UserVal(user_val) => Ok(user_val.value),
_ => Err(()),
})
.collect::<Result<Vec<_>, _>>();
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))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fn increment = (i) => { return i + 1 }

xs = [0..2]
ys = xs
|> map(%, increment)
|> map(%, increment)
10 changes: 9 additions & 1 deletion src/wasm-lib/tests/executor/no_visuals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit f7640e0

Please sign in to comment.