Unreachable Code warning for abstract contract
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Description
When an abstract contract function calls a pure virtual function, and a concrete implementation of that function (in a concrete contracts) reverts, the `Warning: Unreachable code.` is shown which is incorrect/misleading.
## Environment
- Compiler version: commit https://github.com/ethereum/solidity/commit/a1b79de64235f13e6b06e088fe6365c5a12d13d3
## Steps to Reproduce
```solidity
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
abstract contract AbstractContract {
bool public abstractCalled;
error Unimplemented();
function outer() external {
inner();
abstractCalled = true;
}
function inner() internal virtual;
}
contract ChildContract1 is AbstractContract {
bool public wasCalled;
function inner() internal override {
wasCalled = true;
}
}
contract ChildContract2 is AbstractContract {
function inner() internal pure override {
revert Unimplemented();
}
}
```
Gives the error:
```
Warning: Unreachable code.
--> contracts/6_unreachable.sol:11:9:
|
11 | abstractCalled = true;
| ^^^^^^^^^^^^^^^^^^^^^
```
However when `ChildContract1.outer()` is called, the `wasCalled` is correctly set to true. The warning is misleading.
Contributor guide
Research direction
Start by compiling the Solidity reproduction in contracts/6_unreachable.sol with the referenced compiler commit and inspect the unreachable-code diagnostic at line 11. Compare behavior for ChildContract1 and ChildContract2; done means the valid ChildContract1 path no longer receives a misleading warning while the reverting case remains correctly handled.
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