import names are not unified
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Description
The `as` [import keyword](https://docs.soliditylang.org/en/latest/grammar.html#a4.SolidityParser.importDirective) used in `import "./file.sol" as name` creates names considered distinct from other imports of the same file under the same name.
They should be unified when they wrap the exact same file.
## Environment
solc 0.8.28
## Steps to Reproduce
```solidity
// imported.sol
contract C {}
// file1.sol
import "./imported.sol" as Imported;
// file2.sol
import "./imported.sol" as Imported;
// toplevel.sol
import "./file0.sol";
import "./file1.sol";
// Compilation fails with `Identifier already declared`.
```
Contrast the above with the 2 examples below, which both work:
```solidity
// imported.sol
contract C {}
// file1.sol
import {C} from "./imported.sol";
// file2.sol
import {C} from "./imported.sol";
// toplevel.sol
import "./file0.sol";
import "./file1.sol";
// Compilation succeeds.
```
and
```solidity
// imported.sol
contract C {}
// file1.sol
import {C as D} from "./imported.sol";
// file2.sol
import {C as D} from "./imported.sol";
// toplevel.sol
import "./file0.sol";
import "./file1.sol";
// Compilation succeeds.
```
Contributor guide
Research direction
Start by reproducing the failure with solc 0.8.28 using imported.sol, file1.sol, file2.sol, and toplevel.sol from the report, then trace the compiler's import and name-resolution handling. Done means repeated `import "./imported.sol" as Imported` imports are unified when they refer to the exact same file, while the two working examples continue to compile.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100