mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Detect library name clashes.
This commit is contained in:
parent
1cf6acca90
commit
2364c55735
@ -807,7 +807,6 @@ void ExpressionCompiler::endVisit(MemberAccess const& _memberAccess)
|
|||||||
);
|
);
|
||||||
auto contract = dynamic_cast<ContractDefinition const*>(funType->declaration().scope());
|
auto contract = dynamic_cast<ContractDefinition const*>(funType->declaration().scope());
|
||||||
solAssert(contract && contract->isLibrary(), "");
|
solAssert(contract && contract->isLibrary(), "");
|
||||||
//@TODO library name might not be unique
|
|
||||||
m_context.appendLibraryAddress(contract->name());
|
m_context.appendLibraryAddress(contract->name());
|
||||||
m_context << funType->externalIdentifier();
|
m_context << funType->externalIdentifier();
|
||||||
utils().moveIntoStack(funType->selfType()->sizeOnStack(), 2);
|
utils().moveIntoStack(funType->selfType()->sizeOnStack(), 2);
|
||||||
@ -1118,7 +1117,6 @@ void ExpressionCompiler::endVisit(Identifier const& _identifier)
|
|||||||
else if (auto contract = dynamic_cast<ContractDefinition const*>(declaration))
|
else if (auto contract = dynamic_cast<ContractDefinition const*>(declaration))
|
||||||
{
|
{
|
||||||
if (contract->isLibrary())
|
if (contract->isLibrary())
|
||||||
//@todo name should be unique, change once we have module management
|
|
||||||
m_context.appendLibraryAddress(contract->name());
|
m_context.appendLibraryAddress(contract->name());
|
||||||
}
|
}
|
||||||
else if (dynamic_cast<EventDefinition const*>(declaration))
|
else if (dynamic_cast<EventDefinition const*>(declaration))
|
||||||
|
@ -148,6 +148,9 @@ bool CompilerStack::parse()
|
|||||||
m_contracts[contract->name()].contract = contract;
|
m_contracts[contract->name()].contract = contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!checkLibraryNameClashes())
|
||||||
|
noErrors = false;
|
||||||
|
|
||||||
for (Source const* source: m_sourceOrder)
|
for (Source const* source: m_sourceOrder)
|
||||||
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||||
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
@ -400,6 +403,36 @@ void CompilerStack::resolveImports()
|
|||||||
swap(m_sourceOrder, sourceOrder);
|
swap(m_sourceOrder, sourceOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CompilerStack::checkLibraryNameClashes()
|
||||||
|
{
|
||||||
|
bool clashFound = false;
|
||||||
|
map<string, SourceLocation> libraries;
|
||||||
|
for (Source const* source: m_sourceOrder)
|
||||||
|
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
|
||||||
|
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
|
||||||
|
if (contract->isLibrary())
|
||||||
|
{
|
||||||
|
if (libraries.count(contract->name()))
|
||||||
|
{
|
||||||
|
auto err = make_shared<Error>(Error::Type::DeclarationError);
|
||||||
|
*err <<
|
||||||
|
errinfo_sourceLocation(contract->location()) <<
|
||||||
|
errinfo_comment(
|
||||||
|
"Library \"" + contract->name() + "\" declared twice "
|
||||||
|
"(will create ambiguities during linking)."
|
||||||
|
) <<
|
||||||
|
errinfo_secondarySourceLocation(SecondarySourceLocation().append(
|
||||||
|
"The other declaration is here:", libraries[contract->name()]
|
||||||
|
));
|
||||||
|
|
||||||
|
m_errors.push_back(err);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
libraries[contract->name()] = contract->location();
|
||||||
|
}
|
||||||
|
return !clashFound;
|
||||||
|
}
|
||||||
|
|
||||||
string CompilerStack::absolutePath(string const& _path, string const& _reference) const
|
string CompilerStack::absolutePath(string const& _path, string const& _reference) const
|
||||||
{
|
{
|
||||||
// Anything that does not start with `.` is an absolute path.
|
// Anything that does not start with `.` is an absolute path.
|
||||||
|
@ -199,6 +199,9 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void resolveImports();
|
void resolveImports();
|
||||||
|
/// Checks whether there are libraries with the same name, reports that as an error and
|
||||||
|
/// @returns false in this case.
|
||||||
|
bool checkLibraryNameClashes();
|
||||||
/// @returns the absolute path corresponding to @a _path relative to @a _reference.
|
/// @returns the absolute path corresponding to @a _path relative to @a _reference.
|
||||||
std::string absolutePath(std::string const& _path, std::string const& _reference) const;
|
std::string absolutePath(std::string const& _path, std::string const& _reference) const;
|
||||||
/// Compile a single contract and put the result in @a _compiledContracts.
|
/// Compile a single contract and put the result in @a _compiledContracts.
|
||||||
|
Loading…
Reference in New Issue
Block a user