mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow mismatching types in switch cases and detect duplicates by value for number literals.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user