mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Search for shadowee starting from parent scope.
This commit is contained in:
parent
32acadf43d
commit
060d229a22
@ -53,6 +53,7 @@ public:
|
|||||||
bool registerDeclaration(Declaration const& _declaration, ASTString const* _name = nullptr, bool _invisible = false, bool _update = false);
|
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;
|
std::vector<Declaration const*> resolveName(ASTString const& _name, bool _recursive = false) const;
|
||||||
ASTNode const* enclosingNode() const { return m_enclosingNode; }
|
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; }
|
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.
|
/// @returns whether declaration is valid, and if not also returns previous declaration.
|
||||||
Declaration const* conflictingDeclaration(Declaration const& _declaration, ASTString const* _name = nullptr) const;
|
Declaration const* conflictingDeclaration(Declaration const& _declaration, ASTString const* _name = nullptr) const;
|
||||||
|
@ -439,23 +439,6 @@ DeclarationRegistrationHelper::DeclarationRegistrationHelper(
|
|||||||
solAssert(m_currentScope == _currentScope, "Scopes not correctly closed.");
|
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(
|
bool DeclarationRegistrationHelper::registerDeclaration(
|
||||||
DeclarationContainer& _container,
|
DeclarationContainer& _container,
|
||||||
Declaration const& _declaration,
|
Declaration const& _declaration,
|
||||||
@ -469,13 +452,9 @@ bool DeclarationRegistrationHelper::registerDeclaration(
|
|||||||
_errorLocation = &_declaration.location();
|
_errorLocation = &_declaration.location();
|
||||||
|
|
||||||
Declaration const* shadowedDeclaration = nullptr;
|
Declaration const* shadowedDeclaration = nullptr;
|
||||||
if (_warnOnShadow && !_declaration.name().empty())
|
if (_warnOnShadow && !_declaration.name().empty() && _container.enclosingContainer())
|
||||||
for (auto const* decl: _container.resolveName(_declaration.name(), true))
|
for (auto const* decl: _container.enclosingContainer()->resolveName(_declaration.name(), true))
|
||||||
if (decl != &_declaration && !isOverloadedFunction(*decl, _declaration))
|
shadowedDeclaration = decl;
|
||||||
{
|
|
||||||
shadowedDeclaration = decl;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_container.registerDeclaration(_declaration, _name, !_declaration.isVisibleInContract()))
|
if (!_container.registerDeclaration(_declaration, _name, !_declaration.isVisibleInContract()))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user