Merge pull request #8675 from ethereum/disallowOverrideVirtualConstructor

Disallow virtual and override for constructors.
This commit is contained in:
Daniel Kirchner 2020-04-15 16:04:24 +02:00 committed by GitHub
commit 10879bcae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 0 deletions

View File

@ -7,6 +7,7 @@ Compiler Features:
Bugfixes:
* Type Checker: Disallow ``virtual`` and ``override`` for constructors.

View File

@ -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)

View File

@ -0,0 +1,5 @@
contract C {
constructor() override public {}
}
// ----
// TypeError: (17-49): Constructors cannot override.

View File

@ -0,0 +1,5 @@
contract C {
constructor() virtual public {}
}
// ----
// TypeError: (17-48): Constructors cannot be virtual.