diff options
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.cpp | 14 | ||||
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.h | 2 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 14 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.h | 2 |
4 files changed, 16 insertions, 16 deletions
diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index 419ebe93..58dcfe4d 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -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"); +} diff --git a/libsolidity/analysis/ContractLevelChecker.h b/libsolidity/analysis/ContractLevelChecker.h index f930fb60..15cbf45d 100644 --- a/libsolidity/analysis/ContractLevelChecker.h +++ b/libsolidity/analysis/ContractLevelChecker.h @@ -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; }; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index e411609c..9350df05 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -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())); diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index aabda33c..ebfcdadc 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -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); |