mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow using modifiers not in the current contract or in base contracts.
This commit is contained in:
parent
79afd04818
commit
049c7f7a8e
@ -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)
|
||||
|
@ -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.
|
@ -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.
|
@ -0,0 +1,8 @@
|
||||
contract C {
|
||||
modifier m() { _; }
|
||||
}
|
||||
contract D is C {
|
||||
function f() C.m public {
|
||||
}
|
||||
}
|
||||
// ----
|
@ -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.
|
10
test/libsolidity/syntaxTests/modifiers/library_via_using.sol
Normal file
10
test/libsolidity/syntaxTests/modifiers/library_via_using.sol
Normal 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.
|
Loading…
Reference in New Issue
Block a user