Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable Code warning for abstract contract #14359

Open
frontier159 opened this issue Jun 26, 2023 · 0 comments
Open

Unreachable Code warning for abstract contract #14359

frontier159 opened this issue Jun 26, 2023 · 0 comments
Labels
bug 🐛 low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited.

Comments

@frontier159
Copy link

frontier159 commented Jun 26, 2023

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

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.

@ekpyron ekpyron added low effort There is not much implementation work to be done. The task is very easy or tiny. selected for development It's on our short-term development and removed selected for development It's on our short-term development labels Jun 26, 2023
@cameel cameel added the low impact Changes are not very noticeable or potential benefits are limited. label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 low effort There is not much implementation work to be done. The task is very easy or tiny. low impact Changes are not very noticeable or potential benefits are limited.
Projects
None yet
Development

No branches or pull requests

3 participants