From a8c047f48d61a3f27ea37f3b677cc4b1f3cbff3c Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Tue, 8 Aug 2017 18:58:06 -0300 Subject: [PATCH] Enforce commas in tuple syntax --- Changelog.md | 1 + libsolidity/parsing/Parser.cpp | 5 +++-- test/libsolidity/SolidityParser.cpp | 12 ++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3f3d2e987..4609da921 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,7 @@ Features: * Metadata: Store experimental flag in metadata CBOR. Bugfixes: + * Parser: Enforce commas between array and tuple elements. ### 0.4.15 (2017-08-08) diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index a6d6e025a..066e3a29d 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -1300,10 +1300,11 @@ ASTPointer Parser::parsePrimaryExpression() parserError("Expected expression (inline array elements cannot be omitted)."); else components.push_back(ASTPointer()); + if (m_scanner->currentToken() == oppositeToken) break; - else if (m_scanner->currentToken() == Token::Comma) - m_scanner->next(); + + expectToken(Token::Comma); } nodeFactory.markEndPosition(); expectToken(oppositeToken); diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index 2be824d6b..3890ca21d 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -1187,6 +1187,18 @@ BOOST_AUTO_TEST_CASE(tuples) BOOST_CHECK(successParse(text)); } +BOOST_AUTO_TEST_CASE(tuples_without_commas) +{ + char const* text = R"( + contract C { + function f() { + var a = (2 2); + } + } + )"; + CHECK_PARSE_ERROR(text, "Expected token Comma"); +} + BOOST_AUTO_TEST_CASE(member_access_parser_ambiguity) { char const* text = R"(