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

Support inheritance combining constants #15571

Open
3esmit opened this issue Nov 8, 2024 · 1 comment
Open

Support inheritance combining constants #15571

3esmit opened this issue Nov 8, 2024 · 1 comment
Labels

Comments

@3esmit
Copy link
Contributor

3esmit commented Nov 8, 2024

Abstract

I want to be able to do the following inheritance structure:

// SPDX-License-Identifier: MIT-1.0
pragma solidity ^0.8.28;

interface A {
    function FOO() external view returns (uint256);
    function bar() external;
}

abstract contract B { 
    uint256 public constant FOO = 4;
}

contract C is A, B {
    function bar() external {
        //(...)
    }
    //(...)
}

Compiler currently does not like it:

TypeError: Derived contract must override function "FOO". Two or more base classes define function with same name and parameter types. Since one of the bases defines a public state variable which cannot be overridden, you have to change the inheritance layout or the names of the functions.
  --> Test.sol:12:1:
   |
12 | contract C is A, B{
   | ^ (Relevant source part starts here and spans across multiple lines).
Note: Definition in "A": 
 --> Test.sol:5:5:
  |
5 |     function FOO() external view returns (uint256);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note: Definition in "B": 
 --> Test.sol:9:5:
  |
9 |     uint256 public constant FOO = 4;
  |   
@3esmit 3esmit added the feature label Nov 8, 2024
@3esmit
Copy link
Contributor Author

3esmit commented Nov 8, 2024

As workaround, this is the solution:

// SPDX-License-Identifier: MIT-1.0
pragma solidity ^0.8.28;


interface AConstants {
    function FOO() external view returns (uint256);
}

interface A is AConstants {
    function bar() external;
}

abstract contract B is AConstants { 
    uint256 public constant FOO = 4;
}

contract C is A, B {
    function bar() external {
        //(...)
    }
    //(...)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant