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/ContractLevelChecker.cpp | |
parent | 2a85152463e3990d4695978613efddbcebe29b5b (diff) | |
download | dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar.gz dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar.bz2 dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar.lz dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar.xz dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.tar.zst dexon-solidity-4f4f623273052de6ede71bae2696f2388f1aa713.zip |
Move fallback function checks.
Diffstat (limited to 'libsolidity/analysis/ContractLevelChecker.cpp')
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.cpp | 24 |
1 files changed, 24 insertions, 0 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\"."); +} |