diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-04 04:47:13 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-08-05 01:06:23 +0800 |
commit | 32acadf43d655413e65428475a35e7ef3bf8fb78 (patch) | |
tree | bafef82f60ee9630592e7e67540bd67b5da59d83 | |
parent | dc0f85c4fb65fa385bb7145c73cc5edaba195483 (diff) | |
download | dexon-solidity-32acadf43d655413e65428475a35e7ef3bf8fb78.tar dexon-solidity-32acadf43d655413e65428475a35e7ef3bf8fb78.tar.gz dexon-solidity-32acadf43d655413e65428475a35e7ef3bf8fb78.tar.bz2 dexon-solidity-32acadf43d655413e65428475a35e7ef3bf8fb78.tar.lz dexon-solidity-32acadf43d655413e65428475a35e7ef3bf8fb78.tar.xz dexon-solidity-32acadf43d655413e65428475a35e7ef3bf8fb78.tar.zst dexon-solidity-32acadf43d655413e65428475a35e7ef3bf8fb78.zip |
Do not mark overloaded functions as shadowing
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | libsolidity/analysis/NameAndTypeResolver.cpp | 19 | ||||
-rw-r--r-- | libsolidity/analysis/NameAndTypeResolver.h | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 11 |
4 files changed, 32 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index 86cf1058..7d3369f3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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) diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index df83f382..83de2b3e 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -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; diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index a498c7ba..59bd3b1f 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -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; diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 4fe52243..a7aa99df 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -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"( |