Builtin variable inaccessible once shadowed
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Description
When an event named `this` is declared in a contract, the compiler incorrectly resolves all uses of `this` to the event instead of the builtin `this` keyword, even in contexts where an event type is invalid (e.g., `address(this)`).
According to the test file `test/libsolidity/syntaxTests/events/illegal_names_exception.sol`, events are explicitly allowed to shadow builtins like `this` and `super` (with warning 2319). However, the current implementation makes the builtin completely inaccessible once shadowed, rather than using context to disambiguate.
**Expected:** The builtin `this` should be used in value contexts (like `address(this)`), while the event should only be used in `emit` statements.
**Actual:** All uses of `this` resolve to the event, making the builtin inaccessible and causing type errors.
## Environment
- Compiler version: 0.8.30
- Compilation pipeline (legacy, IR, EOF): legacy (default)
- Target EVM version (as per compiler settings): default (prague)
- Framework/IDE (e.g. Foundry, Hardhat, Remix): Command line (solc)
- EVM execution environment / backend / blockchain client: N/A
- Operating system: macOS 14.2 / Linux (tested on both)
## Steps to Reproduce
Create a file `test.sol`:
```solidity
pragma solidity ^0.8.30;
contract C {
event this();
function getAddress() public view returns (address) {
return address(this);
}
}
```
Compile:
```bash
solc test.sol
```
**Output:**
```
Warning: This declaration shadows a builtin symbol.
--> test.sol:5:5:
|
5 | event this();
| ^^^^^^^^^^^^^
Error: Explicit type conversion not allowed from "event this()" to "address".
--> test.sol:8:16:
|
8 | return address(this);
| ^^^^^^^^^^^^^
```
The compiler resolves `this` to the event instead of the builtin, even though the context requires a contract instance.
Contributor guide
Research direction
Run solc on the provided reproducer, then inspect test/libsolidity/syntaxTests/events/illegal_names_exception.sol and the related event name-resolution tests. Add coverage showing that address(this) resolves to the builtin while the shadowing event remains usable in emit statements, and verify the compiler output.
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
- 45/100