mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7807 from ethereum/no-private-override
Disallow use of virtual and private together
This commit is contained in:
commit
a57b12d17d
@ -21,6 +21,7 @@ Breaking changes:
|
||||
* Natspec JSON Interface: Properly support multiple ``@return`` statements in ``@dev`` documentation and enforce named return parameters to be mentioned documentation.
|
||||
* Source mappings: Add "modifier depth" as a fifth field in the source mappings.
|
||||
* AST: Inline assembly is exported as structured JSON instead of plain string.
|
||||
* General: ``private`` cannot be used together with ``virtual``.
|
||||
|
||||
Language Features:
|
||||
* Allow global enums and structs.
|
||||
@ -28,7 +29,7 @@ Language Features:
|
||||
* Allow explicit conversions from ``address`` to ``address payable`` via ``payable(...)``.
|
||||
* Introduce syntax for array slices and implement them for dynamic calldata arrays.
|
||||
* Introduce ``push()`` for dynamic storage arrays. It returns a reference to the newly allocated element, if applicable.
|
||||
* Introduce ``virtual`` and ``override`` keywords
|
||||
* Introduce ``virtual`` and ``override`` keywords.
|
||||
* Modify ``push(element)`` for dynamic storage arrays such that it does not return the new length anymore.
|
||||
* Yul: Introduce ``leave`` statement that exits the current function.
|
||||
|
||||
|
@ -181,8 +181,8 @@ Function Overriding
|
||||
===================
|
||||
|
||||
Base functions can be overridden by inheriting contracts to change their
|
||||
behavior. The overriding function must then use the ``override`` keyword in the
|
||||
function header as shown in this example:
|
||||
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:
|
||||
|
||||
::
|
||||
|
||||
@ -240,6 +240,11 @@ overridden when used with multiple inheritance:
|
||||
// No explicit override required
|
||||
contract D is B, C {}
|
||||
|
||||
.. note::
|
||||
|
||||
Functions with the ``private`` visibility cannot be ``virtual``.
|
||||
|
||||
|
||||
.. _modifier-overriding:
|
||||
|
||||
.. index:: ! overriding;modifier
|
||||
|
@ -327,8 +327,13 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
|
||||
{
|
||||
bool isLibraryFunction = _function.inContractKind() == ContractDefinition::ContractKind::Library;
|
||||
|
||||
if (_function.markedVirtual() && _function.annotation().contract->isInterface())
|
||||
m_errorReporter.warning(_function.location(), "Interface functions are implicitly \"virtual\"");
|
||||
if (_function.markedVirtual())
|
||||
{
|
||||
if (_function.annotation().contract->isInterface())
|
||||
m_errorReporter.warning(_function.location(), "Interface functions are implicitly \"virtual\"");
|
||||
if (_function.visibility() == Declaration::Visibility::Private)
|
||||
m_errorReporter.typeError(_function.location(), "\"virtual\" and \"private\" cannot be used together.");
|
||||
}
|
||||
|
||||
if (_function.isPayable())
|
||||
{
|
||||
|
@ -0,0 +1,8 @@
|
||||
abstract contract A {
|
||||
function test() private virtual returns (uint256);
|
||||
}
|
||||
abstract contract X is A {
|
||||
function test() private override returns (uint256);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (23-73): "virtual" and "private" cannot be used together.
|
Loading…
Reference in New Issue
Block a user