Disallow using modifiers not in the current contract or in base contracts.

This commit is contained in:
chriseth 2020-11-16 20:12:25 +01:00
parent 79afd04818
commit 049c7f7a8e
6 changed files with 59 additions and 0 deletions

View File

@ -630,7 +630,19 @@ void TypeChecker::visitManually(
vector<ASTPointer<VariableDeclaration>> emptyParameterList;
vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr;
if (auto modifierDecl = dynamic_cast<ModifierDefinition const*>(declaration))
{
parameters = &modifierDecl->parameters();
if (auto const* modifierContract = dynamic_cast<ContractDefinition const*>(modifierDecl->scope()))
if (m_currentContract)
{
if (!contains(m_currentContract->annotation().linearizedBaseContracts, modifierContract))
m_errorReporter.typeError(
9428_error,
_modifier.location(),
"Can only use modifiers defined in the current contract or in base contracts."
);
}
}
else
// check parameters for Base constructors
for (ContractDefinition const* base: _bases)

View File

@ -0,0 +1,9 @@
library L {
modifier m() { _; }
}
contract C {
function f() L.m public {
}
}
// ----
// TypeError 9428: (68-71): Can only use modifiers defined in the current contract or in base contracts.

View File

@ -0,0 +1,9 @@
contract C {
modifier m() { _; }
}
contract D {
function f() C.m public {
}
}
// ----
// TypeError 9428: (69-72): Can only use modifiers defined in the current contract or in base contracts.

View File

@ -0,0 +1,8 @@
contract C {
modifier m() { _; }
}
contract D is C {
function f() C.m public {
}
}
// ----

View File

@ -0,0 +1,11 @@
contract A {}
contract C is A {
modifier m() { _; }
}
contract D is A {
function f() C.m public {
}
}
contract T is D, C {}
// ----
// TypeError 9428: (93-96): Can only use modifiers defined in the current contract or in base contracts.

View File

@ -0,0 +1,10 @@
library L {
modifier m() { _; }
}
contract C {
using L for *;
function f() L.m public {
}
}
// ----
// TypeError 9428: (87-90): Can only use modifiers defined in the current contract or in base contracts.