aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYoichi Hirai <i@yoichihirai.com>2016-11-09 21:08:51 +0800
committerYoichi Hirai <i@yoichihirai.com>2016-11-12 00:48:03 +0800
commiteee629652e3ee851419805ad1cb54d168fa77763 (patch)
tree6c0343fc961c133d16491871577f3f6c43c0c24b
parent457daecba1f7e267cf7578b702945bb6532aa2af (diff)
downloaddexon-solidity-eee629652e3ee851419805ad1cb54d168fa77763.tar.gz
dexon-solidity-eee629652e3ee851419805ad1cb54d168fa77763.tar.zst
dexon-solidity-eee629652e3ee851419805ad1cb54d168fa77763.zip
parsing: ban empty enum definition.
-rw-r--r--Changelog.md4
-rw-r--r--libsolidity/parsing/Parser.cpp2
-rw-r--r--test/libsolidity/ASTJSON.cpp14
-rw-r--r--test/libsolidity/SolidityParser.cpp2
4 files changed, 7 insertions, 15 deletions
diff --git a/Changelog.md b/Changelog.md
index b4456a86..4bed85ea 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -5,6 +5,10 @@ Features:
* Type checker: now more eagerly searches for a common type of an inline array with mixed types
* Code generator: generates a runtime error when an out-of-range value is converted into an enum type.
+Bugfixes:
+
+ * Parser: disallow empty enum definitions.
+
### 0.4.4 (2016-10-31)
Bugfixes:
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 52b53619..df3ed7b2 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -406,6 +406,8 @@ ASTPointer<EnumDefinition> Parser::parseEnumDefinition()
if (m_scanner->currentToken() != Token::Identifier)
fatalParserError(string("Expected Identifier after ','"));
}
+ if (members.size() == 0)
+ parserError({"enum with no members is not allowed."});
nodeFactory.markEndPosition();
expectToken(Token::RBrace);
diff --git a/test/libsolidity/ASTJSON.cpp b/test/libsolidity/ASTJSON.cpp
index a0fc5dd7..6c062ee8 100644
--- a/test/libsolidity/ASTJSON.cpp
+++ b/test/libsolidity/ASTJSON.cpp
@@ -94,20 +94,6 @@ BOOST_AUTO_TEST_CASE(using_for_directive)
BOOST_CHECK_EQUAL(usingFor["children"][1]["attributes"]["name"], "uint");
}
-BOOST_AUTO_TEST_CASE(enum_definition)
-{
- CompilerStack c;
- c.addSource("a", "contract C { enum E {} }");
- c.parse();
- map<string, unsigned> sourceIndices;
- sourceIndices["a"] = 1;
- Json::Value astJson = ASTJsonConverter(c.ast("a"), sourceIndices).json();
- Json::Value enumDefinition = astJson["children"][0]["children"][0];
- BOOST_CHECK_EQUAL(enumDefinition["name"], "EnumDefinition");
- BOOST_CHECK_EQUAL(enumDefinition["attributes"]["name"], "E");
- BOOST_CHECK_EQUAL(enumDefinition["src"], "13:9:1");
-}
-
BOOST_AUTO_TEST_CASE(enum_value)
{
CompilerStack c;
diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp
index a81a9828..ec23d5fd 100644
--- a/test/libsolidity/SolidityParser.cpp
+++ b/test/libsolidity/SolidityParser.cpp
@@ -824,7 +824,7 @@ BOOST_AUTO_TEST_CASE(empty_enum_declaration)
contract c {
enum foo { }
})";
- BOOST_CHECK(successParse(text));
+ BOOST_CHECK(!successParse(text));
}
BOOST_AUTO_TEST_CASE(malformed_enum_declaration)