diff options
author | chriseth <chris@ethereum.org> | 2018-11-30 01:29:51 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-11-30 23:30:19 +0800 |
commit | 4f4f623273052de6ede71bae2696f2388f1aa713 (patch) | |
tree | 3fa02d68903944ef7156e71201634fa7da09db3a /libsolidity/analysis | |
parent | 2a85152463e3990d4695978613efddbcebe29b5b (diff) | |
download | dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar.gz dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar.zst dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.zip |
Move fallback function checks.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.cpp | 24 | ||||
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.h | 1 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 20 |
3 files changed, 25 insertions, 20 deletions
diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index 879903de..dd08e181 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -41,6 +41,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract) checkAbstractFunctions(_contract); checkBaseConstructorArguments(_contract); checkConstructor(_contract); + checkFallbackFunction(_contract); return Error::containsOnlyWarnings(m_errorReporter.errors()); } @@ -359,3 +360,26 @@ void ContractLevelChecker::checkConstructor(ContractDefinition const& _contract) if (constructor->visibility() != FunctionDefinition::Visibility::Public && constructor->visibility() != FunctionDefinition::Visibility::Internal) m_errorReporter.typeError(constructor->location(), "Constructor must be public or internal."); } + +void ContractLevelChecker::checkFallbackFunction(ContractDefinition const& _contract) +{ + FunctionDefinition const* fallback = _contract.fallbackFunction(); + if (!fallback) + return; + + if (_contract.isLibrary()) + m_errorReporter.typeError(fallback->location(), "Libraries cannot have fallback functions."); + if (fallback->stateMutability() != StateMutability::NonPayable && fallback->stateMutability() != StateMutability::Payable) + m_errorReporter.typeError( + fallback->location(), + "Fallback function must be payable or non-payable, but is \"" + + stateMutabilityToString(fallback->stateMutability()) + + "\"." + ); + if (!fallback->parameters().empty()) + m_errorReporter.typeError(fallback->parameterList().location(), "Fallback function cannot take parameters."); + if (!fallback->returnParameters().empty()) + m_errorReporter.typeError(fallback->returnParameterList()->location(), "Fallback function cannot return values."); + if (fallback->visibility() != FunctionDefinition::Visibility::External) + m_errorReporter.typeError(fallback->location(), "Fallback function must be defined as \"external\"."); +} diff --git a/libsolidity/analysis/ContractLevelChecker.h b/libsolidity/analysis/ContractLevelChecker.h index 003cfbfd..d6b2808b 100644 --- a/libsolidity/analysis/ContractLevelChecker.h +++ b/libsolidity/analysis/ContractLevelChecker.h @@ -71,6 +71,7 @@ private: ASTNode const* _argumentNode ); void checkConstructor(ContractDefinition const& _contract); + void checkFallbackFunction(ContractDefinition const& _contract); langutil::ErrorReporter& m_errorReporter; }; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 1f88c8ab..1dcb6e65 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -90,26 +90,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract) ASTNode::listAccept(_contract.baseContracts(), *this); - for (FunctionDefinition const* function: _contract.definedFunctions()) - if (function->isFallback()) - { - if (_contract.isLibrary()) - m_errorReporter.typeError(function->location(), "Libraries cannot have fallback functions."); - if (function->stateMutability() != StateMutability::NonPayable && function->stateMutability() != StateMutability::Payable) - m_errorReporter.typeError( - function->location(), - "Fallback function must be payable or non-payable, but is \"" + - stateMutabilityToString(function->stateMutability()) + - "\"." - ); - if (!function->parameters().empty()) - m_errorReporter.typeError(function->parameterList().location(), "Fallback function cannot take parameters."); - if (!function->returnParameters().empty()) - m_errorReporter.typeError(function->returnParameterList()->location(), "Fallback function cannot return values."); - if (function->visibility() != FunctionDefinition::Visibility::External) - m_errorReporter.typeError(function->location(), "Fallback function must be defined as \"external\"."); - } - for (auto const& n: _contract.subNodes()) n->accept(*this); |