diff options
author | Rhett Aultman <roadriverrail@gmail.com> | 2016-11-18 23:37:15 +0800 |
---|---|---|
committer | Rhett Aultman <rhett.aultman@meraki.net> | 2017-01-17 01:32:57 +0800 |
commit | f3a84eab91a6f05cfe58e260f206f9af51811313 (patch) | |
tree | e10cd4452c9bded66869ee8b7975f67ce23343a4 /libsolidity | |
parent | 79e5772b8a18bc4a7a1fd1019604cec6f741b743 (diff) | |
download | dexon-solidity-f3a84eab91a6f05cfe58e260f206f9af51811313.tar.gz dexon-solidity-f3a84eab91a6f05cfe58e260f206f9af51811313.tar.zst dexon-solidity-f3a84eab91a6f05cfe58e260f206f9af51811313.zip |
Error out when contracts collide on name
The previous behaviour, courtesy of the [] operator in std::map, would
uncritically store a new ContractDefinition in m_contracts even when a
ContractDefinition already existed. This "resolved" collissions on contract
names by clobbering the original one with the new one, and could lead to
scenarios where the clobber would only be discovered when the original
ContractDefinition could not be found or referred to, which was an unhelpful
InternalCompilerError.
This change checks the m_contracts map for a collision first and will not let
the ContractDefinition be changed to a new one once it's set, throwing a
CompilerError with information about the conflict.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index a31df584..5d4ccd92 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -180,6 +180,15 @@ bool CompilerStack::parse() if (!resolver.updateDeclaration(*m_globalContext->currentThis())) return false; if (!resolver.updateDeclaration(*m_globalContext->currentSuper())) return false; if (!resolver.resolveNamesAndTypes(*contract)) return false; + if (m_contracts.find(contract->name()) != m_contracts.end()) + { + const ContractDefinition* existingContract = m_contracts.find(contract->name())->second.contract; + if (contract != existingContract) + BOOST_THROW_EXCEPTION(CompilerError() << + errinfo_sourceLocation(contract->location()) << + errinfo_comment(contract->name() + " conflicts with contract at " + + *(existingContract->location().sourceName))); + } m_contracts[contract->name()].contract = contract; } @@ -201,6 +210,16 @@ bool CompilerStack::parse() else noErrors = false; + if (m_contracts.find(contract->name()) != m_contracts.end()) + { + const ContractDefinition* existingContract = m_contracts.find(contract->name())->second.contract; + if (contract != existingContract) + BOOST_THROW_EXCEPTION(CompilerError() << + errinfo_sourceLocation(contract->location()) << + errinfo_comment(contract->name() + " conflicts with!!! contract at " + + *(existingContract->location().sourceName))); + } + m_contracts[contract->name()].contract = contract; } |