From 590e6345ebd9dd6c54091a2ec8e42b016df8138a Mon Sep 17 00:00:00 2001 From: Yash Atreya <44857776+yash-atreya@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:53:06 +0530 Subject: [PATCH] cleanup --- .../sol-macro-expander/src/expand/function.rs | 64 ++++++++++--------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/crates/sol-macro-expander/src/expand/function.rs b/crates/sol-macro-expander/src/expand/function.rs index 64017be19..fccc5bcc3 100644 --- a/crates/sol-macro-expander/src/expand/function.rs +++ b/crates/sol-macro-expander/src/expand/function.rs @@ -40,9 +40,6 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, function: &ItemFunction) -> Result 1; - cx.assert_resolved(parameters)?; if !returns.is_empty() { cx.assert_resolved(returns)?; @@ -105,35 +102,40 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, function: &ItemFunction) -> Result as alloy_sol_types::SolType>::abi_decode_sequence(data, validate) - .map(Into::into) - .map(|r: #return_name| r.#name) - } - } else if is_tuple_noname { - quote! { - as alloy_sol_types::SolType>::abi_decode_sequence(data, validate) - .map(Into::into) - .map(|r: #return_name| { - #tuple_ret - }) + let (return_type, decode_returns) = match returns.len() { + 0 => ( + quote!(#return_name), + quote! { + as alloy_sol_types::SolType>::abi_decode_sequence(data, validate) + .map(Into::into) + }, + ), + 1 => { + let name = anon_name((0, returns.first().unwrap().name.as_ref())); + let ty = cx.expand_rust_type(&returns.first().unwrap().ty); + + ( + ty, + quote! { + as alloy_sol_types::SolType>::abi_decode_sequence(data, validate) + .map(Into::into) + .map(|r: #return_name| r.#name) + }, + ) } - } else { - quote! { - as alloy_sol_types::SolType>::abi_decode_sequence(data, validate) - .map(Into::into) + _ => { + let return_tys = expand_types(returns, cx); + let tuple_ret = generate_return_tuple(returns); + ( + quote!((#(#return_tys),*)), + quote! { + as alloy_sol_types::SolType>::abi_decode_sequence(data, validate) + .map(Into::into) + .map(|r: #return_name| { + #tuple_ret + }) + }, + ) } };