Reproduce
pragma solidity ^0.4.24;
import "./B.sol";
contract A {
B kid;
constructor() public {
kid = new B();
}
}
pragma solidity ^0.4.24;
import "./A.sol";
contract B {
A mom;
constructor() publicv{
mom = A(msg.sender);
}
}
Recommend fix
def unfold_imports(imports, infile):
buffer = []
if infile not in imports:
# should add to traversed paths here.
imports.append(infile)
with open(infile, "r+") as f:
for line in f:
# Remove the pragma line in all imports
if "pragma" in line[:6]:
continue
# Read the imports
if "import" in line[:6]:
match = re.search(r".*[\'|\"](.*)[\'|\"]", line)
if match:
dirname = os.path.dirname(infile)
file = os.path.join(dirname, match.group(1))
absfile = os.path.abspath(file)
buffer.append(unfold_imports(imports, absfile))
# imports.append(absfile)
else:
print("There's syntax error of import in {}".format(infile))
sys.exit(-3)
else:
buffer.append(line)
return ''.join(buffer)
Reproduce
Recommend fix