mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2692 from ethereum/shadowing-overload
Do not mark overloaded functions as shadowing
This commit is contained in:
commit
f3af014afd
@ -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)
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
bool registerDeclaration(Declaration const& _declaration, ASTString const* _name = nullptr, bool _invisible = false, bool _update = false);
|
||||
std::vector<Declaration const*> resolveName(ASTString const& _name, bool _recursive = false) const;
|
||||
ASTNode const* enclosingNode() const { return m_enclosingNode; }
|
||||
DeclarationContainer const* enclosingContainer() const { return m_enclosingContainer; }
|
||||
std::map<ASTString, std::vector<Declaration const*>> const& declarations() const { return m_declarations; }
|
||||
/// @returns whether declaration is valid, and if not also returns previous declaration.
|
||||
Declaration const* conflictingDeclaration(Declaration const& _declaration, ASTString const* _name = nullptr) const;
|
||||
|
@ -452,13 +452,9 @@ bool DeclarationRegistrationHelper::registerDeclaration(
|
||||
_errorLocation = &_declaration.location();
|
||||
|
||||
Declaration const* shadowedDeclaration = nullptr;
|
||||
if (_warnOnShadow && !_declaration.name().empty())
|
||||
for (auto const* decl: _container.resolveName(_declaration.name(), true))
|
||||
if (decl != &_declaration)
|
||||
{
|
||||
shadowedDeclaration = decl;
|
||||
break;
|
||||
}
|
||||
if (_warnOnShadow && !_declaration.name().empty() && _container.enclosingContainer())
|
||||
for (auto const* decl: _container.enclosingContainer()->resolveName(_declaration.name(), true))
|
||||
shadowedDeclaration = decl;
|
||||
|
||||
if (!_container.registerDeclaration(_declaration, _name, !_declaration.isVisibleInContract()))
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -6134,6 +6134,25 @@ BOOST_AUTO_TEST_CASE(shadowing_builtins_with_variables)
|
||||
CHECK_WARNING(text, "shadows a builtin symbol");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(shadowing_builtins_with_storage_variables)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
uint msg;
|
||||
}
|
||||
)";
|
||||
CHECK_WARNING(text, "shadows a builtin symbol");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(shadowing_builtin_at_global_scope)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract msg {
|
||||
}
|
||||
)";
|
||||
CHECK_WARNING(text, "shadows a builtin symbol");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(shadowing_builtins_with_parameters)
|
||||
{
|
||||
char const* text = R"(
|
||||
@ -6190,6 +6209,28 @@ 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(function_override_is_not_shadowing)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract D { function f() {} }
|
||||
contract C is D {
|
||||
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