mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Do not mark overloaded functions as shadowing
This commit is contained in:
parent
dc0f85c4fb
commit
32acadf43d
@ -5,6 +5,7 @@ Features:
|
||||
Bugfixes:
|
||||
* Code Generator: ``.delegatecall()`` should always return execution outcome.
|
||||
* Code Generator: Provide "new account gas" for low-level ``callcode`` and ``delegatecall``.
|
||||
* Type Checker: Do not mark overloaded functions as shadowing other functions.
|
||||
* Type Checker: Disallow the ``.gas()`` modifier on ``ecrecover``, ``sha256`` and ``ripemd160``.
|
||||
|
||||
### 0.4.14 (2017-07-31)
|
||||
|
@ -439,6 +439,23 @@ DeclarationRegistrationHelper::DeclarationRegistrationHelper(
|
||||
solAssert(m_currentScope == _currentScope, "Scopes not correctly closed.");
|
||||
}
|
||||
|
||||
bool DeclarationRegistrationHelper::isOverloadedFunction(
|
||||
Declaration const& _declaration1,
|
||||
Declaration const& _declaration2
|
||||
)
|
||||
{
|
||||
auto const* function1 = dynamic_cast<FunctionDefinition const*>(&_declaration1);
|
||||
auto const* function2 = dynamic_cast<FunctionDefinition const*>(&_declaration2);
|
||||
|
||||
if (!function1 || !function2)
|
||||
return false;
|
||||
|
||||
if (function1->parameters() != function2->parameters())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeclarationRegistrationHelper::registerDeclaration(
|
||||
DeclarationContainer& _container,
|
||||
Declaration const& _declaration,
|
||||
@ -454,7 +471,7 @@ bool DeclarationRegistrationHelper::registerDeclaration(
|
||||
Declaration const* shadowedDeclaration = nullptr;
|
||||
if (_warnOnShadow && !_declaration.name().empty())
|
||||
for (auto const* decl: _container.resolveName(_declaration.name(), true))
|
||||
if (decl != &_declaration)
|
||||
if (decl != &_declaration && !isOverloadedFunction(*decl, _declaration))
|
||||
{
|
||||
shadowedDeclaration = decl;
|
||||
break;
|
||||
|
@ -169,6 +169,8 @@ private:
|
||||
void closeCurrentScope();
|
||||
void registerDeclaration(Declaration& _declaration, bool _opensScope);
|
||||
|
||||
static bool isOverloadedFunction(Declaration const& _declaration1, Declaration const& _declaration2);
|
||||
|
||||
/// @returns the canonical name of the current scope.
|
||||
std::string currentCanonicalName() const;
|
||||
|
||||
|
@ -6190,6 +6190,17 @@ BOOST_AUTO_TEST_CASE(shadowing_builtins_ignores_constructor)
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(function_overload_is_not_shadowing)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
function f() {}
|
||||
function f(uint) {}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS_NO_WARNINGS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(callable_crash)
|
||||
{
|
||||
char const* text = R"(
|
||||
|
Loading…
Reference in New Issue
Block a user