solidity
solidity copied to clipboard
Unreachable Code warning for abstract contract
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
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.
Same here.
In my case, outer() is a modifier, and inner() has that modifier on it.
The annoying thing is that inner() in my case is just a test case (foundry), but the warning is shown in the source. The warning should at least refer to the file that produces the warning.