mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow single statement var decl in if/while/for without blocks
This commit is contained in:
parent
6e5e05779c
commit
4522c804f3
@ -68,6 +68,7 @@ Breaking Changes:
|
|||||||
* Syntax Checker: Named return values in function types are an error.
|
* Syntax Checker: Named return values in function types are an error.
|
||||||
* Syntax Checker: Strictly require visibility specifier for functions. This was already the case in the experimental 0.5.0 mode.
|
* Syntax Checker: Strictly require visibility specifier for functions. This was already the case in the experimental 0.5.0 mode.
|
||||||
* Syntax Checker: Disallow unary ``+``. This was already the case in the experimental 0.5.0 mode.
|
* Syntax Checker: Disallow unary ``+``. This was already the case in the experimental 0.5.0 mode.
|
||||||
|
* Syntax Checker: Disallow single statement variable declaration inside if/while/for without a block.
|
||||||
* View Pure Checker: Strictly enfore state mutability. This was already the case in the experimental 0.5.0 mode.
|
* View Pure Checker: Strictly enfore state mutability. This was already the case in the experimental 0.5.0 mode.
|
||||||
|
|
||||||
Language Features:
|
Language Features:
|
||||||
|
@ -138,9 +138,25 @@ void SyntaxChecker::endVisit(ModifierDefinition const& _modifier)
|
|||||||
m_placeholderFound = false;
|
m_placeholderFound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntaxChecker::visit(WhileStatement const&)
|
void SyntaxChecker::checkSingleStatementVariableDeclaration(ASTNode const* _statement)
|
||||||
|
{
|
||||||
|
auto varDecl = dynamic_cast<VariableDeclarationStatement const*>(_statement);
|
||||||
|
if (varDecl)
|
||||||
|
m_errorReporter.syntaxError(_statement->location(), "Invalid variable declaration. Please declare it inside a block.");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SyntaxChecker::visit(IfStatement const& _ifStatement)
|
||||||
|
{
|
||||||
|
checkSingleStatementVariableDeclaration(&_ifStatement.trueStatement());
|
||||||
|
if (Statement const* _statement = _ifStatement.falseStatement())
|
||||||
|
checkSingleStatementVariableDeclaration(_statement);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SyntaxChecker::visit(WhileStatement const& _whileStatement)
|
||||||
{
|
{
|
||||||
m_inLoopDepth++;
|
m_inLoopDepth++;
|
||||||
|
checkSingleStatementVariableDeclaration(&_whileStatement.body());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,9 +165,10 @@ void SyntaxChecker::endVisit(WhileStatement const&)
|
|||||||
m_inLoopDepth--;
|
m_inLoopDepth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyntaxChecker::visit(ForStatement const&)
|
bool SyntaxChecker::visit(ForStatement const& _forStatement)
|
||||||
{
|
{
|
||||||
m_inLoopDepth++;
|
m_inLoopDepth++;
|
||||||
|
checkSingleStatementVariableDeclaration(&_forStatement.body());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,12 @@ private:
|
|||||||
virtual bool visit(ModifierDefinition const& _modifier) override;
|
virtual bool visit(ModifierDefinition const& _modifier) override;
|
||||||
virtual void endVisit(ModifierDefinition const& _modifier) override;
|
virtual void endVisit(ModifierDefinition const& _modifier) override;
|
||||||
|
|
||||||
|
// Reports an error if _statement is a VariableDeclarationStatement.
|
||||||
|
// Used by if/while/for to check for single statement variable declarations
|
||||||
|
// without a block.
|
||||||
|
void checkSingleStatementVariableDeclaration(ASTNode const* _statement);
|
||||||
|
|
||||||
|
virtual bool visit(IfStatement const& _ifStatement) override;
|
||||||
virtual bool visit(WhileStatement const& _whileStatement) override;
|
virtual bool visit(WhileStatement const& _whileStatement) override;
|
||||||
virtual void endVisit(WhileStatement const& _whileStatement) override;
|
virtual void endVisit(WhileStatement const& _whileStatement) override;
|
||||||
virtual bool visit(ForStatement const& _forStatement) override;
|
virtual bool visit(ForStatement const& _forStatement) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user