From 109a6b85eec323cd8f869788b8e664a5950e8316 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 11 Aug 2021 02:21:30 +0200 Subject: [PATCH] fix: only wrap single struct param in a tuple (#368) --- .../ethers-contract-abigen/src/contract/methods.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs index ec8100a3..dbb8e3a2 100644 --- a/ethers-contract/ethers-contract-abigen/src/contract/methods.rs +++ b/ethers-contract/ethers-contract-abigen/src/contract/methods.rs @@ -80,7 +80,11 @@ pub(crate) fn expand_inputs_call_arg(inputs: &[Param]) -> TokenStream { .map(|(i, param)| { let name = util::expand_input_name(i, ¶m.name); match param.kind { - ParamType::Tuple(_) => { + // this is awkward edge case where the function inputs are a single struct + // we need to force this argument into a tuple so it gets expanded to `((#name,))` + // this is currently necessary because internally `flatten_tokens` is called which removes the outermost `tuple` level + // and since `((#name))` is not a rust tuple it doesn't get wrapped into another tuple that will be peeled off by `flatten_tokens` + ParamType::Tuple(_) if inputs.len() == 1 => { // make sure the tuple gets converted to `Token::Tuple` quote! {(#name,)} }