diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index a26713a73..e59e698f1 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -282,12 +282,15 @@ ASTPointer Parser::parseEnumDefinition() vector> members; expectToken(Token::LBrace); - while (m_scanner->getCurrentToken() == Token::Identifier) + while (m_scanner->getCurrentToken() != Token::RBrace) { members.push_back(parseEnumDeclaration()); if (m_scanner->getCurrentToken() == Token::RBrace) break; expectToken(Token::Comma); + if (m_scanner->getCurrentToken() != Token::Identifier) { + BOOST_THROW_EXCEPTION(createParserError("Expected Identifier after ,")); + } } nodeFactory.markEndPosition(); diff --git a/test/SolidityParser.cpp b/test/SolidityParser.cpp index 291ec6051..07ec2dcfa 100644 --- a/test/SolidityParser.cpp +++ b/test/SolidityParser.cpp @@ -731,6 +731,20 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration) 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() }