mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Better error message for unexpected trailing comma in parameter lists
This commit is contained in:
parent
ccb689701e
commit
0099911ace
@ -1,6 +1,7 @@
|
|||||||
### 0.4.18 (unreleased)
|
### 0.4.18 (unreleased)
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
* Parser: Better error message for unexpected trailing comma in parameter lists.
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
||||||
|
@ -828,6 +828,8 @@ ASTPointer<ParameterList> Parser::parseParameterList(
|
|||||||
parameters.push_back(parseVariableDeclaration(options));
|
parameters.push_back(parseVariableDeclaration(options));
|
||||||
while (m_scanner->currentToken() != Token::RParen)
|
while (m_scanner->currentToken() != Token::RParen)
|
||||||
{
|
{
|
||||||
|
if (m_scanner->currentToken() == Token::Comma && m_scanner->peekNextToken() == Token::RParen)
|
||||||
|
fatalParserError("Unexpected trailing comma in parameter list.");
|
||||||
expectToken(Token::Comma);
|
expectToken(Token::Comma);
|
||||||
parameters.push_back(parseVariableDeclaration(options));
|
parameters.push_back(parseVariableDeclaration(options));
|
||||||
}
|
}
|
||||||
|
@ -167,6 +167,90 @@ BOOST_AUTO_TEST_CASE(single_function_param)
|
|||||||
BOOST_CHECK(successParse(text));
|
BOOST_CHECK(successParse(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(single_function_param_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function(uint a,) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(single_return_param_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function() returns (uint a,) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(single_modifier_arg_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
modifier modTest(uint a,) { _; }
|
||||||
|
function(uint a) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(single_event_arg_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
event Test(uint a,);
|
||||||
|
function(uint a) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(multiple_function_param_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function(uint a, uint b,) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(multiple_return_param_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
function() returns (uint a, uint b,) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(multiple_modifier_arg_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
modifier modTest(uint a, uint b,) { _; }
|
||||||
|
function(uint a) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(multiple_event_arg_trailing_comma)
|
||||||
|
{
|
||||||
|
char const* text = R"(
|
||||||
|
contract test {
|
||||||
|
event Test(uint a, uint b,);
|
||||||
|
function(uint a) {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
CHECK_PARSE_ERROR(text, "Unexpected trailing comma in parameter list.");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_no_body)
|
BOOST_AUTO_TEST_CASE(function_no_body)
|
||||||
{
|
{
|
||||||
char const* text = R"(
|
char const* text = R"(
|
||||||
|
Loading…
Reference in New Issue
Block a user