Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fix: improve overloaded param diff matching (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 11, 2022
1 parent 1655299 commit 3b52c2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ethers-contract/ethers-contract-abigen/src/contract/methods.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{btree_map::Entry, BTreeMap, HashMap};
use std::collections::{btree_map::Entry, BTreeMap, HashMap, HashSet};

use super::{types, util, Context};
use crate::{
Expand Down Expand Up @@ -534,11 +534,21 @@ impl Context {
}
// compare each overloaded function with the `first_fun`
for (idx, overloaded_fun) in functions.into_iter().skip(1) {
// keep track of matched params
let mut already_matched_param_diff = HashSet::new();
// attempt to find diff in the input arguments
let mut diff = Vec::new();
let mut same_params = true;
for (idx, i1) in overloaded_fun.inputs.iter().enumerate() {
if first_fun.inputs.iter().all(|i2| i1 != i2) {
// Find the first param that differs and hasn't already been matched as diff
if let Some((pos, _)) = first_fun
.inputs
.iter()
.enumerate()
.filter(|(pos, _)| !already_matched_param_diff.contains(pos))
.find(|(_, i2)| i1 != *i2)
{
already_matched_param_diff.insert(pos);
diff.push(i1);
same_params = false;
} else {
Expand Down
13 changes: 13 additions & 0 deletions ethers-contract/tests/it/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,16 @@ fn can_generate_event_with_structs() {
assert_eq!("MyEvent((uint256,uint256),uint256)", MyEventFilter::abi_signature());
assert_event::<MyEventFilter>();
}

#[test]
fn can_handle_overloaded_function_with_array() {
abigen!(
Test,
r#"[
serializeString(string calldata, string calldata, string calldata) external returns (string memory)
serializeString(string calldata, string calldata, string[] calldata) external returns (string memory)
serializeBool(string calldata, string calldata, bool) external returns (string memory)
serializeBool(string calldata, string calldata, bool[] calldata) external returns (string memory)
]"#,
);
}

0 comments on commit 3b52c2f

Please sign in to comment.