[AST] Reference id to import directive alias inconsistency
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Description
Import directives allow creating of symbol aliases, for example:
```solidity
import { symbol as symbolAlias } from "./Foo.sol";
```
and source unit aliases:
```solidity
import * as unitAlias from "./Foo.sol";
```
When referencing these aliases through an Identifier node, there is an inconsistency. When referencing `symbolAlias`, referenced declaration AST node ID is the ID of the symbol itself (can be a contract definition, for example) and not the ID of the import directive, where the symbol alias was declared.
When referencing `unitAlias`, referenced declaration AST node ID points to the import directive, where the unit alias was declared and not to the source unit itself.
## Environment
- Compiler version: 0.8.19
- Target EVM version (as per compiler settings): latest
- Framework/IDE (e.g. Truffle or Remix): n/a
- EVM execution environment / backend / blockchain client: n/a
- Operating system: Linux
## Steps to Reproduce
Please see the example here: https://github.com/michprev/solc-ast-import-alias-inconsistency. It contains generated ASTs of all files.
In file A, `Base` (https://github.com/michprev/solc-ast-import-alias-inconsistency/blob/c399cdcda566c5e2b86472422ac5ca47425d8b0b/contracts/A.sol#L8) is an Identifier node and it's referenced declaration ID points to the import directive (https://github.com/michprev/solc-ast-import-alias-inconsistency/blob/c399cdcda566c5e2b86472422ac5ca47425d8b0b/contracts/A.sol#L4).
In file B, `Base2` (https://github.com/michprev/solc-ast-import-alias-inconsistency/blob/c399cdcda566c5e2b86472422ac5ca47425d8b0b/contracts/B.sol#L8) is an Identifier node and it's referenced declaration ID points to the contract definition (https://github.com/michprev/solc-ast-import-alias-inconsistency/blob/c399cdcda566c5e2b86472422ac5ca47425d8b0b/contracts/Base.sol#L4-L6).
This introduces inconsistency - an import directive is referenced from a source unit alias but is not referenced from a symbol alias.
Contributor guide
Research direction
Start with the linked reproduction repository and inspect the generated ASTs for contracts/A.sol and contracts/B.sol, especially the Identifier nodes and their referenced declaration IDs. Trace the Solidity compiler's AST handling for symbol and source-unit import aliases; the fix is complete when both alias forms follow consistent referenced-declaration semantics and the AST examples demonstrate that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- blockchain, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100