mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Move library related checks.
This commit is contained in:
parent
4f992298c6
commit
33d6a24c47
@ -44,6 +44,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract)
|
||||
checkFallbackFunction(_contract);
|
||||
checkExternalTypeClashes(_contract);
|
||||
checkHashCollisions(_contract);
|
||||
checkLibraryRequirements(_contract);
|
||||
|
||||
return Error::containsOnlyWarnings(m_errorReporter.errors());
|
||||
}
|
||||
@ -436,3 +437,16 @@ void ContractLevelChecker::checkHashCollisions(ContractDefinition const& _contra
|
||||
hashes.insert(hash);
|
||||
}
|
||||
}
|
||||
|
||||
void ContractLevelChecker::checkLibraryRequirements(ContractDefinition const& _contract)
|
||||
{
|
||||
if (!_contract.isLibrary())
|
||||
return;
|
||||
|
||||
if (!_contract.baseContracts().empty())
|
||||
m_errorReporter.typeError(_contract.location(), "Library is not allowed to inherit.");
|
||||
|
||||
for (auto const& var: _contract.stateVariables())
|
||||
if (!var->isConstant())
|
||||
m_errorReporter.typeError(var->location(), "Library cannot have non-constant state variables");
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ private:
|
||||
void checkExternalTypeClashes(ContractDefinition const& _contract);
|
||||
/// Checks for hash collisions in external function signatures.
|
||||
void checkHashCollisions(ContractDefinition const& _contract);
|
||||
/// Checks that all requirements for a library are fulfilled if this is a library.
|
||||
void checkLibraryRequirements(ContractDefinition const& _contract);
|
||||
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
};
|
||||
|
@ -93,23 +93,9 @@ bool TypeChecker::visit(ContractDefinition const& _contract)
|
||||
for (auto const& n: _contract.subNodes())
|
||||
n->accept(*this);
|
||||
|
||||
if (_contract.isLibrary())
|
||||
checkLibraryRequirements(_contract);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TypeChecker::checkLibraryRequirements(ContractDefinition const& _contract)
|
||||
{
|
||||
solAssert(_contract.isLibrary(), "");
|
||||
if (!_contract.baseContracts().empty())
|
||||
m_errorReporter.typeError(_contract.location(), "Library is not allowed to inherit.");
|
||||
|
||||
for (auto const& var: _contract.stateVariables())
|
||||
if (!var->isConstant())
|
||||
m_errorReporter.typeError(var->location(), "Library cannot have non-constant state variables");
|
||||
}
|
||||
|
||||
void TypeChecker::checkDoubleStorageAssignment(Assignment const& _assignment)
|
||||
{
|
||||
TupleType const& lhs = dynamic_cast<TupleType const&>(*type(_assignment.leftHandSide()));
|
||||
|
@ -66,8 +66,6 @@ public:
|
||||
private:
|
||||
|
||||
bool visit(ContractDefinition const& _contract) override;
|
||||
/// Checks that all requirements for a library are fulfilled if this is a library.
|
||||
void checkLibraryRequirements(ContractDefinition const& _contract);
|
||||
/// Checks (and warns) if a tuple assignment might cause unexpected overwrites in storage.
|
||||
/// Should only be called if the left hand side is tuple-typed.
|
||||
void checkDoubleStorageAssignment(Assignment const& _assignment);
|
||||
|
Loading…
Reference in New Issue
Block a user