fix: improve overloaded param diff matching (#1853)

This commit is contained in:
Matthias Seitz 2022-11-11 23:25:31 +01:00 committed by GitHub
parent 165529986a
commit 3b52c2fc7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -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::{
@ -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 {

View File

@ -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)
]"#,
);
}