-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
does not support qualified imports
#2545
Comments
this is actually a rather hard problem because the conflicting imports could appear multiple times in the source tree // contract.sol
import "./aux1.sol" as A;
import "./aux2.sol" as B;
// contract2.sol
import "./aux1.sol" as A2;
import "./aux2.sol" as B2;
// contract3.sol
import "./aux1.sol" as Arbitrary0;
import "./aux2.sol" as Arbitrary;
at which point name replace becomes non-trivial in order to support this we'd need to come up with some rules/assumptions to follow for this scenario. I can think of:
|
I would go with "derive name from shortest unambiguous file path" (most likely from So with // src/util/aux.sol
function f() internal {}
// src/utils/c2.sol
import "./aux.sol" as B;
// src/c1.sol
import "./util/aux.sol" as A;
import "./util/c2.sol"; flattening function utils_aux$f() internal {} // first $ separates path from original name (As a note for later, I don't think collapsing multiple qualifiers for one import would break anything (imports are pure) and repeating the code would be super wasteful. The only issue is that I see those multiple qualifiers being used for type safety (say |
Can creating an entry file for flatten to act on not help in this regard? basically creating a barrel contract file? |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (9ed1c37 2022-08-01T00:09:10.803586Z)
What command(s) is the bug in?
forge flatten
Operating System
macOS (Apple Silicon)
Describe the bug
Issue
When a flattened file contains a qualified import (of the form
import path as Q
), then:Q
is not stripped from accesses to definitions found inpath
. For instance,Q.structName
does not becomestructName
.DataType
is imported (with qualifier) from two files, compilation will fail.Suggestion
forge flatten
should strip all qualifiers, and rename definitions as needed (recursively).Example:
forge flatten
results in this (which fails to compile):when it should result in something like
Note: this is kind of a followup to #1440.
The text was updated successfully, but these errors were encountered: