mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow instructions as a switch expression
This commit is contained in:
parent
d745dd6542
commit
c64bd33784
@ -72,6 +72,8 @@ assembly::Statement Parser::parseStatement()
|
||||
assembly::Switch _switch = createWithLocation<assembly::Switch>();
|
||||
m_scanner->next();
|
||||
_switch.expression = make_shared<Statement>(parseExpression());
|
||||
if (_switch.expression->type() == typeid(assembly::Instruction))
|
||||
fatalParserError("Instructions are not supported as expressions for switch.");
|
||||
while (m_scanner->currentToken() == Token::Case)
|
||||
_switch.cases.emplace_back(parseCase());
|
||||
if (m_scanner->currentToken() == Token::Default)
|
||||
|
@ -230,7 +230,6 @@ BOOST_AUTO_TEST_CASE(switch_statement)
|
||||
BOOST_CHECK(successParse("{ switch 42 case 1 {} case 2 {} }"));
|
||||
BOOST_CHECK(successParse("{ switch 42 case 1 {} default {} }"));
|
||||
BOOST_CHECK(successParse("{ switch 42 case 1 {} case 2 {} default {} }"));
|
||||
BOOST_CHECK(successParse("{ 1 2 switch mul case 1 {} case 2 {} default {} }"));
|
||||
BOOST_CHECK(successParse("{ switch mul(1, 2) case 1 {} case 2 {} default {} }"));
|
||||
BOOST_CHECK(successParse("{ function f() -> x {} switch f() case 1 {} case 2 {} default {} }"));
|
||||
}
|
||||
@ -248,6 +247,7 @@ BOOST_AUTO_TEST_CASE(switch_duplicate_case)
|
||||
BOOST_AUTO_TEST_CASE(switch_invalid_expression)
|
||||
{
|
||||
CHECK_PARSE_ERROR("{ switch {} default {} }", ParserError, "Expected elementary inline assembly operation.");
|
||||
CHECK_PARSE_ERROR("{ 1 2 switch mul default {} }", ParserError, "Instructions are not supported as expressions for switch.");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(switch_default_before_case)
|
||||
|
Loading…
Reference in New Issue
Block a user