Merge pull request #7559 from ethereum/inv-code-7488

Disallow call of same-class-ctor as modifier
This commit is contained in:
chriseth 2019-10-23 10:48:44 +02:00 committed by GitHub
commit e56d1aa5aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -8,6 +8,7 @@ Compiler Features:
Bugfixes:
* Type Checker: Disallow constructor of the same class to be used as modifier

View File

@ -390,11 +390,13 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
set<Declaration const*> modifiers;
for (ASTPointer<ModifierInvocation> const& modifier: _function.modifiers())
{
auto baseContracts = dynamic_cast<ContractDefinition const&>(*_function.scope()).annotation().linearizedBaseContracts;
// Delete first base which is just the main contract itself
baseContracts.erase(baseContracts.begin());
visitManually(
*modifier,
_function.isConstructor() ?
dynamic_cast<ContractDefinition const&>(*_function.scope()).annotation().linearizedBaseContracts :
vector<ContractDefinition const*>()
_function.isConstructor() ? baseContracts : vector<ContractDefinition const*>()
);
Declaration const* decl = &dereference(*modifier->name());
if (modifiers.count(decl))

View File

@ -0,0 +1,5 @@
contract C {
constructor() C() public {}
}
// ----
// TypeError: (31-34): Referenced declaration is neither modifier nor base class.