Changed error message and added tests

This commit is contained in:
Leonardo Alt 2018-09-04 11:48:58 +02:00
parent 4522c804f3
commit 17176871ab
6 changed files with 59 additions and 1 deletions

View File

@ -142,7 +142,7 @@ void SyntaxChecker::checkSingleStatementVariableDeclaration(ASTNode const* _stat
{
auto varDecl = dynamic_cast<VariableDeclarationStatement const*>(_statement);
if (varDecl)
m_errorReporter.syntaxError(_statement->location(), "Invalid variable declaration. Please declare it inside a block.");
m_errorReporter.syntaxError(_statement->location(), "Variable declarations can only be used inside blocks.");
}
bool SyntaxChecker::visit(IfStatement const& _ifStatement)

View File

@ -0,0 +1,12 @@
pragma solidity >0.4.24;
contract C
{
function f(uint x) public pure {
do
uint y;
while (x > 0);
}
}
// ----
// SyntaxError: (81-87): Variable declarations can only be used inside blocks.

View File

@ -0,0 +1,13 @@
pragma solidity >0.4.24;
contract C
{
function f(uint x) public pure {
if (x > 0)
{uint y;}
else
uint z;
}
}
// ----
// SyntaxError: (109-115): Variable declarations can only be used inside blocks.

View File

@ -0,0 +1,11 @@
pragma solidity >0.4.24;
contract C
{
function f(uint x) public pure {
for (uint i = 0; i < x; ++i)
uint y;
}
}
// ----
// SyntaxError: (107-113): Variable declarations can only be used inside blocks.

View File

@ -0,0 +1,11 @@
pragma solidity >0.4.24;
contract C
{
function f(uint x) public pure {
if (x > 0)
uint y;
}
}
// ----
// SyntaxError: (89-95): Variable declarations can only be used inside blocks.

View File

@ -0,0 +1,11 @@
pragma solidity >0.4.24;
contract C
{
function f(uint x) public pure {
while (x > 0)
uint y;
}
}
// ----
// SyntaxError: (92-98): Variable declarations can only be used inside blocks.