mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7559 from ethereum/inv-code-7488
Disallow call of same-class-ctor as modifier
This commit is contained in:
commit
e56d1aa5aa
@ -8,6 +8,7 @@ Compiler Features:
|
||||
|
||||
|
||||
Bugfixes:
|
||||
* Type Checker: Disallow constructor of the same class to be used as modifier
|
||||
|
||||
|
||||
|
||||
|
@ -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))
|
||||
|
@ -0,0 +1,5 @@
|
||||
contract C {
|
||||
constructor() C() public {}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (31-34): Referenced declaration is neither modifier nor base class.
|
Loading…
Reference in New Issue
Block a user