core icon indicating copy to clipboard operation
core copied to clipboard

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

Open makcandrov opened this issue 1 year ago • 2 comments

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);
  |                  ^^^^^^^^

makcandrov avatar Apr 13 '24 04:04 makcandrov

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

DaniPopes avatar Apr 13 '24 17:04 DaniPopes

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;
   |                      ^

makcandrov avatar Apr 14 '24 03:04 makcandrov