diff options
author | chriseth <chris@ethereum.org> | 2018-11-30 01:26:53 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-11-30 23:30:19 +0800 |
commit | 2a85152463e3990d4695978613efddbcebe29b5b (patch) | |
tree | 9403a55686f1ef6bb49d1877a2c1b34dc31e6242 /libsolidity/analysis | |
parent | b610be4882ca77defb73e35eda93996ca790f9f4 (diff) | |
download | dexon-solidity-2a85152463e3990d4695978613efddbcebe29b5b.tar dexon-solidity-2a85152463e3990d4695978613efddbcebe29b5b.tar.gz dexon-solidity-2a85152463e3990d4695978613efddbcebe29b5b.tar.bz2 dexon-solidity-2a85152463e3990d4695978613efddbcebe29b5b.tar.lz dexon-solidity-2a85152463e3990d4695978613efddbcebe29b5b.tar.xz dexon-solidity-2a85152463e3990d4695978613efddbcebe29b5b.tar.zst dexon-solidity-2a85152463e3990d4695978613efddbcebe29b5b.zip |
Move constructor checks.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.cpp | 20 | ||||
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.h | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 16 |
3 files changed, 21 insertions, 16 deletions
diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index 0ddb198f..879903de 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -40,6 +40,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract) checkIllegalOverrides(_contract); checkAbstractFunctions(_contract); checkBaseConstructorArguments(_contract); + checkConstructor(_contract); return Error::containsOnlyWarnings(m_errorReporter.errors()); } @@ -339,3 +340,22 @@ void ContractLevelChecker::annotateBaseConstructorArguments( } } + +void ContractLevelChecker::checkConstructor(ContractDefinition const& _contract) +{ + FunctionDefinition const* constructor = _contract.constructor(); + if (!constructor) + return; + + if (!constructor->returnParameters().empty()) + m_errorReporter.typeError(constructor->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor."); + if (constructor->stateMutability() != StateMutability::NonPayable && constructor->stateMutability() != StateMutability::Payable) + m_errorReporter.typeError( + constructor->location(), + "Constructor must be payable or non-payable, but is \"" + + stateMutabilityToString(constructor->stateMutability()) + + "\"." + ); + if (constructor->visibility() != FunctionDefinition::Visibility::Public && constructor->visibility() != FunctionDefinition::Visibility::Internal) + m_errorReporter.typeError(constructor->location(), "Constructor must be public or internal."); +} diff --git a/libsolidity/analysis/ContractLevelChecker.h b/libsolidity/analysis/ContractLevelChecker.h index eb8807e9..003cfbfd 100644 --- a/libsolidity/analysis/ContractLevelChecker.h +++ b/libsolidity/analysis/ContractLevelChecker.h @@ -70,6 +70,7 @@ private: FunctionDefinition const* _baseConstructor, ASTNode const* _argumentNode ); + void checkConstructor(ContractDefinition const& _contract); langutil::ErrorReporter& m_errorReporter; }; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 3572943b..1f88c8ab 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -90,22 +90,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract) ASTNode::listAccept(_contract.baseContracts(), *this); - FunctionDefinition const* function = _contract.constructor(); - if (function) - { - if (!function->returnParameters().empty()) - m_errorReporter.typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor."); - if (function->stateMutability() != StateMutability::NonPayable && function->stateMutability() != StateMutability::Payable) - m_errorReporter.typeError( - function->location(), - "Constructor must be payable or non-payable, but is \"" + - stateMutabilityToString(function->stateMutability()) + - "\"." - ); - if (function->visibility() != FunctionDefinition::Visibility::Public && function->visibility() != FunctionDefinition::Visibility::Internal) - m_errorReporter.typeError(function->location(), "Constructor must be public or internal."); - } - for (FunctionDefinition const* function: _contract.definedFunctions()) if (function->isFallback()) { |