In code like the below, address public balance has an automatic getter function (as can be seen in the corresponding ABI).

However we need to redefine it to avoid the compiler complaining that Test does not fully implement ITest.

Any idea if this is a bug or a feature (and if so why)?

pragma solidity ^0.4.24;

interface ITest {
    function balance() external returns (address);

contract Test is ITest {
    address public balance;

    // Why is this function needed?
    function balance() public returns (address) {
        return balance;
  • I think this is considered a bug in the Solidity compiler, but I haven't seen anyone say when/if it will be fixed. – user19510 Aug 21 '18 at 1:06

As of the official docs of the 0.4.24 compiler version :

any contract with a function without an implementation, is an abstract contract automatically. If you inherit from an abstract contract, you will have to implement all functions that are not implemented in the parent contract.

Interfaces are exactly the same, only that you need to implement all functions defined in the interface ( since it doesn't implement any function at all ), thus the necessity of implementing the Balance().

for the state variable Balance It would be better if you changed the name and tested the outcome, it may be just a name collusion ( even if that looks not easy to happen ).

  • I think the point is that address public balance does implement the interface function balance() external returns (address);, but the compiler doesn't seem to understand that. – user19510 Aug 21 '18 at 1:07
  • Yep - exactly. State variables which are public get automatic getter functions (which appear in the contracts ABI) - trying to understand if there is a good reason these are not recognised as matching the interface (vs. a bug / slightly broken implementation). – Adam Dossa Aug 21 '18 at 8:18
  • I am still pretty sure it is just a naming collision, where a Balance function is mandatory from the interface inheritance. It just happens to have the same name as a state variable balance. In case this is true, it should be noted in a warning by the compiler. – Kaki Master Of Time Aug 21 '18 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.