-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow cyclic imports. #2665
Comments
I was not able to reproduce your problem. Cyclic imports should be supported by the compiler. Could you tell me more about how you invoke it? |
Above two files at
Result:
Compiler version:
|
Ok, I was able to reproduce it, but only with standard-json. I suspect this has something to do with trailing slashes and that the compiler does not recognize that two files are indeed identical. @axic could you please take a look? |
This is turning out to be a pretty significant problem for Augur's migration to Solidity. Is there anything we can do to facilitate getting this fixed sooner rather than later? We could attempt to create a PR if someone can point us in the right direction both for how to author a failing test case (e.g., exmaple of how to author such a test) and where the likely source of the problem is. Of course, as always with open source projects the time to ramp up a new person enough to fix even a minor bug is sometimes higher than just fixing it yourself, so I'll leave it to you to decide if this is simple enough for someone who has no idea how any of the Solidity code base works to fix. |
Ok, this does not fix it yet, but I think you should change |
Ah no, it does fix it! So I think this is not a bug after all. Files are not identified by the source they are loaded from but by the name they are given in the input json. If you import |
If I understand you correctly @chriseth, you are saying that remapping is done after checking to see if the file is already imported? So in this case, I'm bringing in Assuming that the Assuming that works, should I open a separate issue to apply remappings and absolute file pathing before noting the file as loaded, so all loaded files use the absolute file path as the lookup key, rather than mixing relative, absolute, and remapped files? |
@chriseth I just tried changing my JSON to:
Unfortunately, the compiler errors because it doesn't see that as a valid path. This means that the proposed workaround doesn't work. :/ |
It is the |
@axic Can you give an example of what you mean? When I was trying to figure out how to get the standard-json working, the only way I could get it to work with local files was in the above way. Are you suggesting that I shouldn't be including the
|
|
I think you have to use |
I changed |
Actually, let me dig a tad more before I assert that it didn't work. |
I dug in a bit more and the proposed change of using the absolute file path for the What is of note is that I only have problems when viewing (compiling) files that include themselves transitively. If I open (compile) a file that transitively includes a file that then transitively includes itself there is no problem. This aligns with what you two were saying and suggests that the file being passed to the compiler for compilation isn't being keyed the same as a file that is later imported. |
OK, I have resolved my issue, but I believe there is still a bug in solc. In the end, my issue was a path separator inconsistency on Windows, where some places were using Sorry about the thrash, let me know if you would like me to open a new issue (feature request?) for the above. |
Yes I think it would be clearer to have its own dedicated issue. If you create that can we also consider this one closed? |
Also there's this other issue you may encounter: #2147. |
Parent.sol
Child.sol
In this scenario, the circular dependency is safe because neither is creating/deriving from the other. However, the imports quickly get confused trying to import each other. It would be nice if it supported graphs like this as it is a fairly common pattern.
It should be noted that this problem does not occur if both contracts are placed in the same file. This suggests to me that the compiler can handle this scenario, it just gets confused by the cyclic imports.
In the meantime, I'm open to ideas for workarounds. I considered extracting out interfaces for each but in that case the interfaces would have the same problem because fundamentally I am using this cycle to deal with cross-contract access control like
require(_providedChild == parent.child())
.The text was updated successfully, but these errors were encountered: