Check for use of modifiers in invalid contexts

This commit is contained in:
Mathias Baumann 2019-10-21 13:18:19 +02:00
parent ad7cf42aad
commit 8c5d1da5a5
3 changed files with 27 additions and 1 deletions

View File

@ -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;
}

View File

@ -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;
};

View File

@ -0,0 +1,9 @@
contract test {
modifier mod() { _; }
function f() public {
mod ;
}
}
// ----
// TypeError: (77-80): Modifier can only be referenced in function headers.