Disallow mismatching types in switch cases and detect duplicates by value for number literals.

This commit is contained in:
Daniel Kirchner
2019-01-15 16:32:21 +01:00
parent f9ca5b78fb
commit 4c8f8e9491
16 changed files with 166 additions and 30 deletions
+1 -1
View File
@@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(switch_no_cases)
BOOST_AUTO_TEST_CASE(switch_duplicate_case)
{
CHECK_PARSE_ERROR("{ switch 42 case 1 {} case 1 {} default {} }", DeclarationError, "Duplicate case defined");
CHECK_PARSE_ERROR("{ switch 42 case 1 {} case 1 {} default {} }", DeclarationError, "Duplicate case defined.");
}
BOOST_AUTO_TEST_CASE(switch_invalid_expression)
+13
View File
@@ -304,6 +304,19 @@ BOOST_AUTO_TEST_CASE(if_statement_invalid)
BOOST_CHECK(successParse("{ if 42:u256 { } }"));
}
BOOST_AUTO_TEST_CASE(switch_case_types)
{
CHECK_ERROR("{ switch 0:u256 case 0:u256 {} case 1:u32 {} }", TypeError, "Switch cases have non-matching types.");
// The following should be an error in the future, but this is not yet detected.
BOOST_CHECK(successParse("{ switch 0:u256 case 0:u32 {} case 1:u32 {} }"));
}
BOOST_AUTO_TEST_CASE(switch_duplicate_case)
{
CHECK_ERROR("{ switch 0:u256 case 0:u256 {} case 0x0:u256 {} }", DeclarationError, "Duplicate case defined.");
BOOST_CHECK(successParse("{ switch 0:u256 case 42:u256 {} case 0x42:u256 {} }"));
}
BOOST_AUTO_TEST_CASE(builtins_parser)
{
struct SimpleDialect: public Dialect