diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-25 22:36:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-25 22:36:34 +0800 |
commit | a72237f2754258ca385eee88bddfa4de3fce8d8f (patch) | |
tree | a6a6b5b32c0471d91ce21cfe748be3b9f10ba5a0 | |
parent | e6bbbb330c6f8d7075a125ed963a72efa2bf0035 (diff) | |
parent | 0099911ace631789ab8a2294710b9fd57af1c478 (diff) | |
download | dexon-solidity-a72237f2754258ca385eee88bddfa4de3fce8d8f.tar.gz dexon-solidity-a72237f2754258ca385eee88bddfa4de3fce8d8f.tar.zst dexon-solidity-a72237f2754258ca385eee88bddfa4de3fce8d8f.zip |
Merge pull request #2954 from wadeAlexC/develop
Better message for unexpected trailing commas in parameter lists
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/parsing/Parser.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityParser.cpp | 84 |
3 files changed, 87 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md index 3d185ccb..9755d2d3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ ### 0.4.18 (unreleased) Features: + * Parser: Better error message for unexpected trailing comma in parameter lists. Bugfixes: diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index ce8a9f01..9a8bb358 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -828,6 +828,8 @@ ASTPointer<ParameterList> Parser::parseParameterList( parameters.push_back(parseVariableDeclaration(options)); 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); parameters.push_back(parseVariableDeclaration(options)); } diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index a8698d13..72473c3e 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -167,6 +167,90 @@ BOOST_AUTO_TEST_CASE(single_function_param) 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) { char const* text = R"( |