mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Allow overrides to have a more strict mutability than super
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user