Reputation: 5657
Let's say I have contract Parent.sol
which has two imports:
import "./interfaces/IPair.sol";
import "./interfaces/IMasterChef.sol";
And both interfaces individually import IERC20.sol
.
Well when I compile Parent.sol
, I'll get declaration error due to repeateded import of IERC20.sol
:
contracts/Parent.sol:7:1: DeclarationError: Identifier already declared.
import "./interfaces/IMasterChef.sol";
^------------------------------------^
contracts/interfaces/IERC20.sol:4:1: The previous declaration is here:
interface IERC20 {
^ (Relevant source part starts here and spans across multiple lines).
Error HH600: Compilation failed
Is there any way of solving this without flattening the file?
Upvotes: 0
Views: 521
Reputation: 43521
There's currently no namespacing or import X as Y
, that would allow to use both interfaces with the same name.
If you don't want to merge the files, you can keep both but need to change the actual interface name of at least one them.
Example:
./interfaces/IPair.sol
imports ./Pair/IERC20.sol
, which defines interface IERC20 {}
interface IPairERC20 {}
and all occurrences that instantiate it (new IERC20()
to new IPairERC20()
)./interfaces/IMasterChef.sol
imports ./MasterChef/IERC20.sol
, which defines interface IERC20 {}
interface IMasterChefERC20 {}
and all occurrences that instantiate it (new IERC20()
to new IMasterChefERC20()
)Upvotes: 1