alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
763 stars 137 forks source link

[Bug] Cannot define functions with the same signature in different contracts/interfaces #599

Closed makcandrov closed 1 month ago

makcandrov commented 5 months ago

Component

sol! macro

What version of Alloy are you on?

0.7.0

Operating System

None

Describe the bug

alloy_sol_types::sol! {
    interface IERC20 {
        function transfer(address to, uint256 value) external returns (bool);
    }

    interface IERC721 {
        function transfer(address to, uint256 tokenId) external returns (bool);
    }
}
error: function with same name and parameter types defined twice

         = note: other declaration is here

 --> src\main.rs:3:18
  |
3 |         function transfer(address to, uint256 value) external returns (bool);
  |                  ^^^^^^^^
DaniPopes commented 5 months ago

You should be able to work around this for now by creating separate sol! invocations for each interface.

makcandrov commented 5 months ago

It doesn't work when you need to share something (like a structure) between the interfaces

alloy_sol_types::sol! {
    struct S {
        uint256 s;
    }

    interface Foo {
        function foo(S memory s) external;
    }

}

alloy_sol_types::sol! {
    interface Bar {
        function foo(S memory s) external;
    }
}
error: unresolved type

         = help: Custom types must be declared inside of the same scope they are referenced in,
       or "imported" as a UDT with `type ... is (...);`

  --> src\main.rs:14:22
   |
14 |         function foo(S memory s) external;
   |                      ^

error: unresolved custom type: S
  --> src\main.rs:14:22
   |
14 |         function foo(S memory s) external;
   |                      ^