mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Better error messages for invalid switch cases
This commit is contained in:
parent
c64bd33784
commit
05fcf1989c
@ -78,6 +78,10 @@ assembly::Statement Parser::parseStatement()
|
||||
_switch.cases.emplace_back(parseCase());
|
||||
if (m_scanner->currentToken() == Token::Default)
|
||||
_switch.cases.emplace_back(parseCase());
|
||||
if (m_scanner->currentToken() == Token::Default)
|
||||
fatalParserError("Only one default case allowed.");
|
||||
else if (m_scanner->currentToken() == Token::Case)
|
||||
fatalParserError("Case not allowed after default case.");
|
||||
if (_switch.cases.size() == 0)
|
||||
fatalParserError("Switch statement without any cases.");
|
||||
_switch.location.end = _switch.cases.back().body.location.end;
|
||||
|
@ -252,12 +252,12 @@ BOOST_AUTO_TEST_CASE(switch_invalid_expression)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_default_before_case)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 default {} case 1 {} }", ParserError, "Expected elementary inline assembly operation.");
|
||||
CHECK_PARSE_ERROR("{ switch 42 default {} case 1 {} }", ParserError, "Case not allowed after default case.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_duplicate_default_case)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch 42 default {} default {} }", ParserError, "Expected elementary inline assembly operation.");
|
||||
CHECK_PARSE_ERROR("{ switch 42 default {} default {} }", ParserError, "Only one default case allowed.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_invalid_case)
|
||||
|
Loading…
Reference in New Issue
Block a user