mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6542 from hydai/yul/string_literal_too_long
[Yul] Output an error of a switch case which contains string literals…
This commit is contained in:
commit
27d0481958
@ -442,15 +442,21 @@ bool AsmAnalyzer::operator()(Switch const& _switch)
|
|||||||
if (_case.value)
|
if (_case.value)
|
||||||
{
|
{
|
||||||
int const initialStackHeight = m_stackHeight;
|
int const initialStackHeight = m_stackHeight;
|
||||||
|
bool isCaseValueValid = true;
|
||||||
// We cannot use "expectExpression" here because *_case.value is not a
|
// We cannot use "expectExpression" here because *_case.value is not a
|
||||||
// Statement and would be converted to a Statement otherwise.
|
// Statement and would be converted to a Statement otherwise.
|
||||||
if (!(*this)(*_case.value))
|
if (!(*this)(*_case.value))
|
||||||
|
{
|
||||||
|
isCaseValueValid = false;
|
||||||
success = false;
|
success = false;
|
||||||
|
}
|
||||||
expectDeposit(1, initialStackHeight, _case.value->location);
|
expectDeposit(1, initialStackHeight, _case.value->location);
|
||||||
m_stackHeight--;
|
m_stackHeight--;
|
||||||
|
|
||||||
|
// If the case value is not valid, we should not insert it into cases.
|
||||||
|
yulAssert(isCaseValueValid || m_errorReporter.hasErrors(), "Invalid case value.");
|
||||||
/// Note: the parser ensures there is only one default case
|
/// Note: the parser ensures there is only one default case
|
||||||
if (!cases.insert(valueOfLiteral(*_case.value)).second)
|
if (isCaseValueValid && !cases.insert(valueOfLiteral(*_case.value)).second)
|
||||||
{
|
{
|
||||||
m_errorReporter.declarationError(
|
m_errorReporter.declarationError(
|
||||||
_case.location,
|
_case.location,
|
||||||
|
@ -390,6 +390,12 @@ BOOST_AUTO_TEST_CASE(switch_duplicate_case_different_literal)
|
|||||||
BOOST_CHECK(successParse("{ switch 1:u256 case \"1\":u256 {} case \"2\":u256 {} }"));
|
BOOST_CHECK(successParse("{ switch 1:u256 case \"1\":u256 {} case \"2\":u256 {} }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(switch_case_string_literal_too_long)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(successParse("{let x:u256 switch x case \"01234567890123456789012345678901\":u256 {}}"));
|
||||||
|
CHECK_ERROR("{let x:u256 switch x case \"012345678901234567890123456789012\":u256 {}}", TypeError, "String literal too long (33 > 32)");
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(function_shadowing_outside_vars)
|
BOOST_AUTO_TEST_CASE(function_shadowing_outside_vars)
|
||||||
{
|
{
|
||||||
CHECK_ERROR("{ let x:u256 function f() -> x:u256 {} }", DeclarationError, "already taken in this scope");
|
CHECK_ERROR("{ let x:u256 function f() -> x:u256 {} }", DeclarationError, "already taken in this scope");
|
||||||
|
Loading…
Reference in New Issue
Block a user