mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Return the last contract by default.
This commit is contained in:
parent
5a1a83ff42
commit
a98afc8eaa
@ -234,9 +234,13 @@ CompilerStack::Contract const& CompilerStack::getContract(string const& _contrac
|
|||||||
{
|
{
|
||||||
if (m_contracts.empty())
|
if (m_contracts.empty())
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("No compiled contracts found."));
|
||||||
|
string contractName = _contractName;
|
||||||
if (_contractName.empty())
|
if (_contractName.empty())
|
||||||
return m_contracts.begin()->second;
|
// try to find the "last contract"
|
||||||
auto it = m_contracts.find(_contractName);
|
for (ASTPointer<ASTNode> const& node: m_sourceOrder.back()->ast->getNodes())
|
||||||
|
if (auto contract = dynamic_cast<ContractDefinition const*>(node.get()))
|
||||||
|
contractName = contract->getName();
|
||||||
|
auto it = m_contracts.find(contractName);
|
||||||
if (it == m_contracts.end())
|
if (it == m_contracts.end())
|
||||||
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract " + _contractName + " not found."));
|
BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Contract " + _contractName + " not found."));
|
||||||
return it->second;
|
return it->second;
|
||||||
|
Loading…
Reference in New Issue
Block a user