-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
forge flatten duplication of interfaces/contract names #262 #4034
Comments
Hi @gakonst @mattsse - our migration to forge is nearly complete, with the exception of this issue. Foundry needs to be able to rename interfaces in flattened contracts to prevent collisions. For example, if we have For example, this contract has the I've also been informed about Foundry flattening sometimes having issues due to duplicate licenses. Someone shared the following code snipped with me as they have said it fixes the issues most of the time:
I understand that this is a separate issue however I wanted to raise it here. I am aiming for us to migrate our spells to foundry before the end of the month - this is the last issue we are having at the moment. |
@Evalir Just bumping this issue as it still seems to be present. Here's another repro for you:
|
It seems like the flattening breaks on the level of ethers-rs package and not in foundry. So The issue was also raised there: gakonst/ethers-rs#2588 |
fixing this properly would require resolving all imports/usages and renaming everything accordingly.
do you mean it generates the exact same interface twice, or does this happen when the project imports two identical interfaces? |
It happens when project imports two interfaces with the same name (but they don't have to be identical besides the name). I think this external issue gakonst/ethers-rs#2588 clearly outlines what happens. Here is the except from it:
|
Add `Hash` derive for `SourceLocation`, fix schema for `TryCatchClause` and add test for it. I am currently working on foundry-rs/foundry#4034 and it requires usage of native solc AST, so I might be opening some other PRs around it as it seems that we are not using current models anywhere and they might be a bit outdated
Ref foundry-rs/foundry#4034. ## Solution solang-parser AST was not sufficient to rename stuff, because it doesn't collect IDs of declarations and we can't match specific identifier to the declaration. Native solc AST gives such ability, so I've implemented native solc AST visitor. The implementation of flattening itself consits of several steps: 1. Find all sources that are needed for target (imports of any depth). 2. Expore ASTs for all sources and find all top-level declarations (contracts, events, structs, etc). 3. Find if any top-level declarations names are same 4. If any duplicates are found, figure out new names for them (e.g. 2 `OracleLike` interfaces become `OracleLike_0` and `OracleLike_1`) 5. Walk AST and find all references to top-level declarations. Replace every reference with declaration name. We should update names even for unchanged declarations to deal with aliased imports. 6. Collect and remove all import directives. 7. Collect and remove all pragmas and license identifiers. This flattener implementation can be a full replacer of the current impl for all cases when source being flattened can be compiled via solc.
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (a44159a 2023-01-02T00:04:45.597843Z)
What command(s) is the bug in?
forge flatten
Operating System
macOS (Apple Silicon)
Describe the bug
When running
forge flatten <file>
in a project that the path of files includes multiple interfaces/contracts with the same name, the command can't solve the duplication and just generate the output with the same name repeated.For example if running
forge flatten
command in this file: https://github.com/makerdao/spells-goerli/blob/solc-0.8/src/DssSpell.sol will generate the result with twoOracleLike
interfaces.Hevm
would have producedOracleLike_1
andOracleLike_2
instead.The text was updated successfully, but these errors were encountered: