Skip to content

Commit d86c94f

Browse files
committed
Require modifiers to contain "_".
1 parent c389f89 commit d86c94f

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

libsolidity/analysis/SyntaxChecker.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,26 @@ void SyntaxChecker::syntaxError(SourceLocation const& _location, std::string con
4040
m_errors.push_back(err);
4141
}
4242

43+
bool SyntaxChecker::visit(ModifierDefinition const&)
44+
{
45+
m_placeholderFound = false;
46+
return true;
47+
}
48+
49+
void SyntaxChecker::endVisit(ModifierDefinition const& _modifier)
50+
{
51+
if (!m_placeholderFound)
52+
syntaxError(_modifier.body().location(), "Modifier body does not contain '_'.");
53+
m_placeholderFound = false;
54+
}
55+
4356
bool SyntaxChecker::visit(WhileStatement const&)
4457
{
4558
m_inLoopDepth++;
4659
return true;
4760
}
4861

49-
void SyntaxChecker::endVisit(WhileStatement const&)
62+
void SyntaxChecker::endVisit(WhileStatement const& )
5063
{
5164
m_inLoopDepth--;
5265
}
@@ -78,3 +91,9 @@ bool SyntaxChecker::visit(Break const& _breakStatement)
7891
return true;
7992
}
8093

94+
bool SyntaxChecker::visit(const PlaceholderStatement&)
95+
{
96+
m_placeholderFound = true;
97+
return true;
98+
}
99+

libsolidity/analysis/SyntaxChecker.h

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace solidity
3131
/**
3232
* The module that performs syntax analysis on the AST:
3333
* - whether continue/break is in a for/while loop.
34+
* - whether a modifier contains at least one '_'
3435
*/
3536
class SyntaxChecker: private ASTConstVisitor
3637
{
@@ -44,6 +45,9 @@ class SyntaxChecker: private ASTConstVisitor
4445
/// Adds a new error to the list of errors.
4546
void syntaxError(SourceLocation const& _location, std::string const& _description);
4647

48+
virtual bool visit(ModifierDefinition const& _modifier) override;
49+
virtual void endVisit(ModifierDefinition const& _modifier) override;
50+
4751
virtual bool visit(WhileStatement const& _whileStatement) override;
4852
virtual void endVisit(WhileStatement const& _whileStatement) override;
4953
virtual bool visit(ForStatement const& _forStatement) override;
@@ -52,8 +56,13 @@ class SyntaxChecker: private ASTConstVisitor
5256
virtual bool visit(Continue const& _continueStatement) override;
5357
virtual bool visit(Break const& _breakStatement) override;
5458

59+
virtual bool visit(PlaceholderStatement const& _placeholderStatement) override;
60+
5561
ErrorList& m_errors;
5662

63+
/// Flag that indicates whether a function modifier actually contains '_'.
64+
bool m_placeholderFound = false;
65+
5766
int m_inLoopDepth = 0;
5867
};
5968

test/libsolidity/SolidityNameAndTypeResolution.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -3823,6 +3823,16 @@ BOOST_AUTO_TEST_CASE(unused_return_value_delegatecall)
38233823
BOOST_CHECK(expectError(text, true) == Error::Type::Warning);
38243824
}
38253825

3826+
BOOST_AUTO_TEST_CASE(modifier_without_underscore)
3827+
{
3828+
char const* text = R"(
3829+
contract test {
3830+
modifier m() {}
3831+
}
3832+
)";
3833+
BOOST_CHECK(expectError(text, true) == Error::Type::SyntaxError);
3834+
}
3835+
38263836
BOOST_AUTO_TEST_SUITE_END()
38273837

38283838
}

0 commit comments

Comments
 (0)