- 
                Notifications
    
You must be signed in to change notification settings  - Fork 6.2k
 
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:
pragma solidity ^0.8.30;
contract C {
    event this();
    
    function getAddress() public view returns (address) {
        return address(this);
    }
}Compile:
solc test.solOutput:
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.