mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Check for use of modifiers in invalid contexts
This commit is contained in:
parent
ad7cf42aad
commit
8c5d1da5a5
@ -524,7 +524,12 @@ void TypeChecker::visitManually(
|
||||
_modifier.arguments() ? *_modifier.arguments() : std::vector<ASTPointer<Expression>>();
|
||||
for (ASTPointer<Expression> const& argument: arguments)
|
||||
argument->accept(*this);
|
||||
_modifier.name()->accept(*this);
|
||||
|
||||
{
|
||||
m_insideModifierInvocation = true;
|
||||
ScopeGuard resetFlag{[&] () { m_insideModifierInvocation = false; }};
|
||||
_modifier.name()->accept(*this);
|
||||
}
|
||||
|
||||
auto const* declaration = &dereference(*_modifier.name());
|
||||
vector<ASTPointer<VariableDeclaration>> emptyParameterList;
|
||||
@ -2387,6 +2392,15 @@ bool TypeChecker::visit(Identifier const& _identifier)
|
||||
);
|
||||
}
|
||||
|
||||
if (!m_insideModifierInvocation)
|
||||
if (ModifierType const* type = dynamic_cast<decltype(type)>(_identifier.annotation().type))
|
||||
{
|
||||
m_errorReporter.typeError(
|
||||
_identifier.location(),
|
||||
"Modifier can only be referenced in function headers."
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -166,6 +166,9 @@ private:
|
||||
/// Flag indicating whether we are currently inside a StructDefinition.
|
||||
bool m_insideStruct = false;
|
||||
|
||||
/// Flag indicating whether we are currently inside the invocation of a modifier
|
||||
bool m_insideModifierInvocation = false;
|
||||
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
};
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
contract test {
|
||||
modifier mod() { _; }
|
||||
|
||||
function f() public {
|
||||
mod ;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (77-80): Modifier can only be referenced in function headers.
|
Loading…
Reference in New Issue
Block a user