重复进口报关错误如何解决?
How to solve declaration error due to repeated imports?
假设我有合同 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
有什么方法可以解决此问题而不 压缩文件吗?
目前没有命名空间或 import X as Y
允许使用同名的两个接口。
如果不想合并文件,可以保留两个文件,但至少需要更改其中一个文件的实际接口名称。
示例:
./interfaces/IPair.sol
导入 ./Pair/IERC20.sol
,定义 interface IERC20 {}
- 将定义更改为
interface IPairERC20 {}
以及实例化它的所有实例(new IERC20()
到 new IPairERC20()
)
./interfaces/IMasterChef.sol
导入 ./MasterChef/IERC20.sol
,定义 interface IERC20 {}
- 将定义更改为
interface IMasterChefERC20 {}
以及实例化它的所有实例(new IERC20()
到 new IMasterChefERC20()
)
假设我有合同 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
有什么方法可以解决此问题而不 压缩文件吗?
目前没有命名空间或 import X as Y
允许使用同名的两个接口。
如果不想合并文件,可以保留两个文件,但至少需要更改其中一个文件的实际接口名称。
示例:
./interfaces/IPair.sol
导入./Pair/IERC20.sol
,定义interface IERC20 {}
- 将定义更改为
interface IPairERC20 {}
以及实例化它的所有实例(new IERC20()
到new IPairERC20()
)
- 将定义更改为
./interfaces/IMasterChef.sol
导入./MasterChef/IERC20.sol
,定义interface IERC20 {}
- 将定义更改为
interface IMasterChefERC20 {}
以及实例化它的所有实例(new IERC20()
到new IMasterChefERC20()
)
- 将定义更改为