Allow overrides to have a more strict mutability than super

This commit is contained in:
Mathias Baumann
2020-07-16 17:55:12 +02:00
parent 052c4a86a0
commit dfffecfe2c
13 changed files with 113 additions and 8 deletions
+10 -4
View File
@@ -203,23 +203,29 @@ Function Overriding
Base functions can be overridden by inheriting contracts to change their
behavior if they are marked as ``virtual``. The overriding function must then
use the ``override`` keyword in the function header as shown in this example:
use the ``override`` keyword in the function header.
The overriding function may only change the visibility of the overridden function from ``external`` to ``public``.
The mutability may be changed to a more strict one following the order:
``nonpayable`` can be overridden by ``view`` and ``pure``. ``view`` can be overridden by ``pure``.
``payable`` is an exception and cannot be changed to any other mutability.
The following example demonstrates changing mutability and visibility:
::
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.8.0;
pragma solidity >0.6.99 <0.8.0;
contract Base
{
function foo() virtual public {}
function foo() virtual external view {}
}
contract Middle is Base {}
contract Inherited is Middle
{
function foo() public override {}
function foo() override public pure {}
}
For multiple inheritance, the most derived base contracts that define the same