Skip to content

Commit

Permalink
Enforce commas in tuple syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
federicobond authored and axic committed Aug 11, 2017
1 parent 5b26e2b commit a8c047f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions libsolidity/parsing/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,11 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
parserError("Expected expression (inline array elements cannot be omitted).");
else
components.push_back(ASTPointer<Expression>());

if (m_scanner->currentToken() == oppositeToken)
break;
else if (m_scanner->currentToken() == Token::Comma)
m_scanner->next();

expectToken(Token::Comma);
}
nodeFactory.markEndPosition();
expectToken(oppositeToken);
Expand Down
12 changes: 12 additions & 0 deletions test/libsolidity/SolidityParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"(
Expand Down

0 comments on commit a8c047f

Please sign in to comment.