diff options
author | chriseth <chris@ethereum.org> | 2018-07-12 06:05:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-12 06:05:32 +0800 |
commit | 99bee7e233f86ce0820176ce97a7ecd3d629ab17 (patch) | |
tree | 2c9c371d5741703be05dd7e4f505bd82d3d98e4f /libsolidity | |
parent | 2b8091526fa3e3f50fff2271fecabc44edbb5375 (diff) | |
parent | cee4775a589bc0047bc505b82fc174ddf07b703d (diff) | |
download | dexon-solidity-99bee7e233f86ce0820176ce97a7ecd3d629ab17.tar.gz dexon-solidity-99bee7e233f86ce0820176ce97a7ecd3d629ab17.tar.zst dexon-solidity-99bee7e233f86ce0820176ce97a7ecd3d629ab17.zip |
Merge pull request #4443 from ethereum/double_var_decl_fix
Fix crash when declaring the same var twice in the same scope
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/DeclarationContainer.cpp | 5 | ||||
-rw-r--r-- | libsolidity/analysis/DeclarationContainer.h | 3 | ||||
-rw-r--r-- | libsolidity/analysis/NameAndTypeResolver.cpp | 8 |
3 files changed, 15 insertions, 1 deletions
diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp index 786272e4..9e2bf6d3 100644 --- a/libsolidity/analysis/DeclarationContainer.cpp +++ b/libsolidity/analysis/DeclarationContainer.cpp @@ -96,6 +96,11 @@ void DeclarationContainer::activateVariable(ASTString const& _name) m_invisibleDeclarations.erase(_name); } +bool DeclarationContainer::isInvisible(ASTString const& _name) const +{ + return m_invisibleDeclarations.count(_name); +} + bool DeclarationContainer::registerDeclaration( Declaration const& _declaration, ASTString const* _name, diff --git a/libsolidity/analysis/DeclarationContainer.h b/libsolidity/analysis/DeclarationContainer.h index a3e0bd0a..9d7a17a3 100644 --- a/libsolidity/analysis/DeclarationContainer.h +++ b/libsolidity/analysis/DeclarationContainer.h @@ -62,6 +62,9 @@ public: /// VariableDeclarationStatements. void activateVariable(ASTString const& _name); + /// @returns true if declaration is currently invisible. + bool isInvisible(ASTString const& _name) const; + /// @returns existing declaration names similar to @a _name. /// Searches this and all parent containers. std::vector<ASTString> similarNames(ASTString const& _name) const; diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index b856544a..7c23c992 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -156,7 +156,13 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration) void NameAndTypeResolver::activateVariable(string const& _name) { solAssert(m_currentScope, ""); - m_currentScope->activateVariable(_name); + // Scoped local variables are invisible before activation. + // When a local variable is activated, its name is removed + // from a scope's invisible variables. + // This is used to avoid activation of variables of same name + // in the same scope (an error is returned). + if (m_currentScope->isInvisible(_name)) + m_currentScope->activateVariable(_name); } vector<Declaration const*> NameAndTypeResolver::resolveName(ASTString const& _name, ASTNode const* _scope) const |