Skip to content

Commit

Permalink
fix: fallible systems using extra arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ten3roberts committed Nov 30, 2024
1 parent 4ffc4d9 commit af418c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
20 changes: 15 additions & 5 deletions flax-derive/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,27 @@ pub(crate) fn system_impl(
.map(|i| format_ident!("__extra_arg_{i}"))
.collect_vec();

let call = if *ret == ReturnType::Default {
quote! { #call_sig(#(#query_idents),* #(,#with_adapters #item_names)* ) }
let (call_expr, ret_sig, ret) = if *ret == ReturnType::Default {
(
quote! { #call_sig(#(#query_idents),* #(,#with_adapters #item_names)* ) },
quote! { () },
quote! {},
)
} else {
quote! { #call_sig(#(#query_idents),* #(,#with_adapters #item_names)* )?; }
(
quote! { #call_sig(#(#query_idents),* #(,#with_adapters #item_names)* )?; },
quote! { #crate_name::__internal::anyhow::Result<()> },
quote! { Ok(()) },
)
};

quote! {
build(|#(mut #item_names: #items_types,)* mut main_query: #crate_name::QueryBorrow<'_, _, _>| {
build(|#(mut #item_names: #items_types,)* mut main_query: #crate_name::QueryBorrow<'_, _, _>| -> #ret_sig {
for (#(#query_idents,)*) in &mut main_query {
#call
#call_expr
}

#ret
})
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,8 @@ pub(crate) use vtable::ComponentVTable;
#[doc(inline)]
#[cfg(feature = "derive")]
pub use flax_derive::*;

#[doc(hidden)]
pub mod __internal {
pub use anyhow;
}
7 changes: 5 additions & 2 deletions tests/system_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ fn system_macro() {
eprintln!("{a} {b} {c_renamed} {d:?}");
}

#[system(par)]
fn fallible(a: &mut i32) -> anyhow::Result<()> {
#[system(filter(a().with()), with_cmd_mut)]
fn fallible(a: &mut i32, _cmd: &mut CommandBuffer) -> anyhow::Result<()> {
(anyhow::Ok(()))?;

let _ = a;

Ok(())
}

Expand Down

0 comments on commit af418c9

Please sign in to comment.