mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8675 from ethereum/disallowOverrideVirtualConstructor
Disallow virtual and override for constructors.
This commit is contained in:
commit
10879bcae6
@ -7,6 +7,7 @@ Compiler Features:
|
||||
|
||||
|
||||
Bugfixes:
|
||||
* Type Checker: Disallow ``virtual`` and ``override`` for constructors.
|
||||
|
||||
|
||||
|
||||
|
@ -1796,6 +1796,10 @@ void TypeChecker::typeCheckReceiveFunction(FunctionDefinition const& _function)
|
||||
void TypeChecker::typeCheckConstructor(FunctionDefinition const& _function)
|
||||
{
|
||||
solAssert(_function.isConstructor(), "");
|
||||
if (_function.markedVirtual())
|
||||
m_errorReporter.typeError(_function.location(), "Constructors cannot be virtual.");
|
||||
if (_function.overrides())
|
||||
m_errorReporter.typeError(_function.location(), "Constructors cannot override.");
|
||||
if (!_function.returnParameters().empty())
|
||||
m_errorReporter.typeError(_function.returnParameterList()->location(), "Non-empty \"returns\" directive for constructor.");
|
||||
if (_function.stateMutability() != StateMutability::NonPayable && _function.stateMutability() != StateMutability::Payable)
|
||||
|
@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
constructor() override public {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (17-49): Constructors cannot override.
|
@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
constructor() virtual public {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (17-48): Constructors cannot be virtual.
|
Loading…
Reference in New Issue
Block a user