Skip to content

Incorrect warning about unreachable code. #10620

@blishko

Description

@blishko

Description

For the following example

abstract contract A {
    bool s;

    function f() public view mod {
        assert(s); // holds for C, but fails for B
    }
    modifier mod() virtual;
}

contract B is A {
    modifier mod() virtual override {
        s = false;
        _;
    }
}

contract C is B {
    modifier mod() override {
        s = true;
        _;
    }
}

The compiler reports the following warning:

Warning: Unreachable code.
 --> /Users/mblicha/projects/solidity/build/test.sol:4:34:
  |
4 |     function f() public view mod {
  |                                  ^ (Relevant source part starts here and spans across multiple lines).

This warning is very confusing and most likely also incorrect. I would expect this to be compiled without any warning.

Environment

  • Compiler version: 0.7.5, also current develop
  • Target EVM version (as per compiler settings): N/A
  • Framework/IDE (e.g. Truffle or Remix): N/A
  • EVM execution environment / backend / blockchain client: N/A
  • Operating system: MacOs 10.13

Steps to Reproduce

Just compile with solc.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions