2

One of the breaking changes of solidity 0.5 was making explicit function visibility mandatory, hence all interface functions must be defined as external today.

In solidity 0.6, there seems to be two new function modifiers introduced: virtual and override.

How do they overlap with the previous rules for interface functions?

1

Answer

There are two new rules to be aware of:

  1. All interface functions are implicitly virtual. If you want to be explicit about it, the compiler throws a warning.
  2. All functions inheriting from the interface must set the override modifier on every function that overrides an interface function, lest the compiler throws an error.

Example

Try to see what happens if you add virtual or remove override from this:

interface MyInterface {

    function getBlockNumber() external view returns (uint256);
}

contract MyContract is MyInterface {

    function getBlockNumber() public view override returns (uint256) {
        return block.number;
    }
}

Further Documentation

Note that the virtual and override modifiers don't apply only to interfaces. I recommend reading more about them in this other thread and the solidity 0.6 breaking changes docs.

| improve this answer | |

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.