mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Properly detect name clashes with functions before their definition.
This commit is contained in:
parent
db7b38e3c4
commit
b4cd2d6a93
@ -7,6 +7,7 @@ Compiler Features:
|
|||||||
|
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
* Yul: Properly detect name clashes with functions before their declaration.
|
||||||
|
|
||||||
|
|
||||||
Build System:
|
Build System:
|
||||||
|
@ -150,7 +150,14 @@ bool ScopeFiller::operator()(Block const& _block)
|
|||||||
scope(&_block).superScope = m_currentScope;
|
scope(&_block).superScope = m_currentScope;
|
||||||
m_currentScope = &scope(&_block);
|
m_currentScope = &scope(&_block);
|
||||||
|
|
||||||
|
// First visit all functions to make them create
|
||||||
|
// an entry in the scope according to their visibility.
|
||||||
for (auto const& s: _block.statements)
|
for (auto const& s: _block.statements)
|
||||||
|
if (s.type() == typeid(FunctionDefinition))
|
||||||
|
if (!boost::apply_visitor(*this, s))
|
||||||
|
success = false;
|
||||||
|
for (auto const& s: _block.statements)
|
||||||
|
if (s.type() != typeid(FunctionDefinition))
|
||||||
if (!boost::apply_visitor(*this, s))
|
if (!boost::apply_visitor(*this, s))
|
||||||
success = false;
|
success = false;
|
||||||
|
|
||||||
|
@ -428,7 +428,31 @@ BOOST_AUTO_TEST_CASE(opcode_for_function_args)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(name_clashes)
|
BOOST_AUTO_TEST_CASE(name_clashes)
|
||||||
{
|
{
|
||||||
CHECK_PARSE_ERROR("{ let g := 2 function g() { } }", DeclarationError, "Function name g already taken in this scope");
|
CHECK_PARSE_ERROR("{ let g := 2 function g() { } }", DeclarationError, "Variable name g already taken in this scope");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(name_clashes_function_subscope)
|
||||||
|
{
|
||||||
|
CHECK_PARSE_ERROR("{ function g() { function g() {} } }", DeclarationError, "Function name g already taken in this scope");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(name_clashes_function_subscope_reverse)
|
||||||
|
{
|
||||||
|
CHECK_PARSE_ERROR("{ { function g() {} } function g() { } }", DeclarationError, "Function name g already taken in this scope");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(name_clashes_function_variable_subscope)
|
||||||
|
{
|
||||||
|
CHECK_PARSE_ERROR("{ function g() { let g := 0 } }", DeclarationError, "Variable name g already taken in this scope");
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(name_clashes_function_variable_subscope_reverse)
|
||||||
|
{
|
||||||
|
CHECK_PARSE_ERROR("{ { let g := 0 } function g() { } }", DeclarationError, "Variable name g already taken in this scope");
|
||||||
|
}
|
||||||
|
BOOST_AUTO_TEST_CASE(functions_in_parallel_scopes)
|
||||||
|
{
|
||||||
|
BOOST_CHECK(successParse("{ { function g() {} } { function g() {} } }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(variable_access_cross_functions)
|
BOOST_AUTO_TEST_CASE(variable_access_cross_functions)
|
||||||
|
Loading…
Reference in New Issue
Block a user