Browse Source

Disallow trailing comma in Enum Declaration

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
31014b3457
  1. 5
      libsolidity/Parser.cpp
  2. 14
      test/SolidityParser.cpp

5
libsolidity/Parser.cpp

@ -282,12 +282,15 @@ ASTPointer<EnumDefinition> Parser::parseEnumDefinition()
vector<ASTPointer<EnumDeclaration>> members; vector<ASTPointer<EnumDeclaration>> members;
expectToken(Token::LBrace); expectToken(Token::LBrace);
while (m_scanner->getCurrentToken() == Token::Identifier) while (m_scanner->getCurrentToken() != Token::RBrace)
{ {
members.push_back(parseEnumDeclaration()); members.push_back(parseEnumDeclaration());
if (m_scanner->getCurrentToken() == Token::RBrace) if (m_scanner->getCurrentToken() == Token::RBrace)
break; break;
expectToken(Token::Comma); expectToken(Token::Comma);
if (m_scanner->getCurrentToken() != Token::Identifier) {
BOOST_THROW_EXCEPTION(createParserError("Expected Identifier after ,"));
}
} }
nodeFactory.markEndPosition(); nodeFactory.markEndPosition();

14
test/SolidityParser.cpp

@ -731,6 +731,20 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration)
BOOST_CHECK_NO_THROW(parseTextExplainError(text)); BOOST_CHECK_NO_THROW(parseTextExplainError(text));
} }
BOOST_AUTO_TEST_CASE(malformed_enum_declaration)
{
char const* text = R"(
contract c {
enum foo { WARNING,};
function c ()
{
a = foo.CRITICAL;
}
uint256 a;
})";
BOOST_CHECK_THROW(parseText(text), ParserError);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
} }

Loading…
Cancel
Save