diff options
author | chriseth <chris@ethereum.org> | 2018-11-30 01:32:06 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-11-30 23:30:19 +0800 |
commit | 6d1644e55c03850341e6bfcc4ae46f8de264a039 (patch) | |
tree | ba5f90d16bd45555d25f3e5e56a78d80bb3f09a1 /libsolidity | |
parent | 4f4f623273052de6ede71bae2696f2388f1aa713 (diff) | |
download | dexon-solidity-6d1644e55c03850341e6bfcc4ae46f8de264a039.tar.gz dexon-solidity-6d1644e55c03850341e6bfcc4ae46f8de264a039.tar.zst dexon-solidity-6d1644e55c03850341e6bfcc4ae46f8de264a039.zip |
Move external type clash check.
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.cpp | 37 | ||||
-rw-r--r-- | libsolidity/analysis/ContractLevelChecker.h | 3 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 37 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.h | 3 |
4 files changed, 40 insertions, 40 deletions
diff --git a/libsolidity/analysis/ContractLevelChecker.cpp b/libsolidity/analysis/ContractLevelChecker.cpp index dd08e181..e2208f3f 100644 --- a/libsolidity/analysis/ContractLevelChecker.cpp +++ b/libsolidity/analysis/ContractLevelChecker.cpp @@ -42,6 +42,7 @@ bool ContractLevelChecker::check(ContractDefinition const& _contract) checkBaseConstructorArguments(_contract); checkConstructor(_contract); checkFallbackFunction(_contract); + checkExternalTypeClashes(_contract); return Error::containsOnlyWarnings(m_errorReporter.errors()); } @@ -383,3 +384,39 @@ void ContractLevelChecker::checkFallbackFunction(ContractDefinition const& _cont if (fallback->visibility() != FunctionDefinition::Visibility::External) m_errorReporter.typeError(fallback->location(), "Fallback function must be defined as \"external\"."); } + +void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _contract) +{ + map<string, vector<pair<Declaration const*, FunctionTypePointer>>> externalDeclarations; + for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts) + { + for (FunctionDefinition const* f: contract->definedFunctions()) + if (f->isPartOfExternalInterface()) + { + auto functionType = make_shared<FunctionType>(*f); + // under non error circumstances this should be true + if (functionType->interfaceFunctionType()) + externalDeclarations[functionType->externalSignature()].push_back( + make_pair(f, functionType->asCallableFunction(false)) + ); + } + for (VariableDeclaration const* v: contract->stateVariables()) + if (v->isPartOfExternalInterface()) + { + auto functionType = make_shared<FunctionType>(*v); + // under non error circumstances this should be true + if (functionType->interfaceFunctionType()) + externalDeclarations[functionType->externalSignature()].push_back( + make_pair(v, functionType->asCallableFunction(false)) + ); + } + } + for (auto const& it: externalDeclarations) + for (size_t i = 0; i < it.second.size(); ++i) + for (size_t j = i + 1; j < it.second.size(); ++j) + if (!it.second[i].second->hasEqualParameterTypes(*it.second[j].second)) + m_errorReporter.typeError( + it.second[j].first->location(), + "Function overload clash during conversion to external types for arguments." + ); +} diff --git a/libsolidity/analysis/ContractLevelChecker.h b/libsolidity/analysis/ContractLevelChecker.h index d6b2808b..ef148617 100644 --- a/libsolidity/analysis/ContractLevelChecker.h +++ b/libsolidity/analysis/ContractLevelChecker.h @@ -72,6 +72,9 @@ private: ); void checkConstructor(ContractDefinition const& _contract); void checkFallbackFunction(ContractDefinition const& _contract); + /// Checks that different functions with external visibility end up having different + /// external argument types (i.e. different signature). + void checkExternalTypeClashes(ContractDefinition const& _contract); langutil::ErrorReporter& m_errorReporter; }; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 1dcb6e65..d107d2dc 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -93,7 +93,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract) for (auto const& n: _contract.subNodes()) n->accept(*this); - checkContractExternalTypeClashes(_contract); // check for hash collisions in function signatures set<FixedHash<4>> hashes; for (auto const& it: _contract.interfaceFunctionList()) @@ -113,42 +112,6 @@ bool TypeChecker::visit(ContractDefinition const& _contract) return false; } -void TypeChecker::checkContractExternalTypeClashes(ContractDefinition const& _contract) -{ - map<string, vector<pair<Declaration const*, FunctionTypePointer>>> externalDeclarations; - for (ContractDefinition const* contract: _contract.annotation().linearizedBaseContracts) - { - for (FunctionDefinition const* f: contract->definedFunctions()) - if (f->isPartOfExternalInterface()) - { - auto functionType = make_shared<FunctionType>(*f); - // under non error circumstances this should be true - if (functionType->interfaceFunctionType()) - externalDeclarations[functionType->externalSignature()].push_back( - make_pair(f, functionType->asCallableFunction(false)) - ); - } - for (VariableDeclaration const* v: contract->stateVariables()) - if (v->isPartOfExternalInterface()) - { - auto functionType = make_shared<FunctionType>(*v); - // under non error circumstances this should be true - if (functionType->interfaceFunctionType()) - externalDeclarations[functionType->externalSignature()].push_back( - make_pair(v, functionType->asCallableFunction(false)) - ); - } - } - for (auto const& it: externalDeclarations) - for (size_t i = 0; i < it.second.size(); ++i) - for (size_t j = i + 1; j < it.second.size(); ++j) - if (!it.second[i].second->hasEqualParameterTypes(*it.second[j].second)) - m_errorReporter.typeError( - it.second[j].first->location(), - "Function overload clash during conversion to external types for arguments." - ); -} - void TypeChecker::checkLibraryRequirements(ContractDefinition const& _contract) { solAssert(_contract.isLibrary(), ""); diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index d5ccb263..aabda33c 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -66,9 +66,6 @@ public: private: bool visit(ContractDefinition const& _contract) override; - /// Checks that different functions with external visibility end up having different - /// external argument types (i.e. different signature). - void checkContractExternalTypeClashes(ContractDefinition const& _contract); /// 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. |