Solidity 如何解决重复导入导致的声明错误?
假设我有一个contractSolidity 如何解决重复导入导致的声明错误?,solidity,Solidity,假设我有一个contractParent.sol,它有两个导入: import "./interfaces/IPair.sol"; import "./interfaces/IMasterChef.sol"; 两个接口分别导入IERC20.sol 当我编译Parent.sol时,由于重复导入IERC20.sol,我将得到声明错误: contracts/Parent.sol:7:1: DeclarationError: Identifier already
Parent.sol
,它有两个导入:
import "./interfaces/IPair.sol";
import "./interfaces/IMasterChef.sol";
两个接口分别导入IERC20.sol
当我编译Parent.sol
时,由于重复导入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
有没有办法在不展平文件的情况下解决此问题?目前没有名称空间或
将X导入为Y
,这将允许使用具有相同名称的两个接口
如果不想合并文件,可以保留这两个文件,但至少需要更改其中一个文件的实际接口名 例如:
导入/interfaces/IPair.sol
,它定义了/Pair/IERC20.sol
接口IERC20{}
- 将定义更改为
以及实例化它的所有实例(interface ipairrc20{}
更改为new IERC20()
)new ipairrc20()
- 将定义更改为
导入/interfaces/IMasterChef.sol
,它定义了/MasterChef/IERC20.sol
接口IERC20{}
- 将定义更改为
以及实例化它的所有实例(interface IMasterChefERC20{}
更改为new IERC20()
)new IMasterChefERC20()
- 将定义更改为