Solidity 如何解决重复导入导致的声明错误?

Solidity 如何解决重复导入导致的声明错误?,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

假设我有一个contract
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()

感谢您的支持-可惜还没有名称空间!