diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2019-01-17 23:37:36 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2019-01-18 19:12:23 +0800 |
commit | b7a86a124d658f0723f576e0f447773f3bec148b (patch) | |
tree | a9623176d79ac797bd609bec4e4c62778b70bb08 | |
parent | a766efc79fbcdf0aa2fc9210b20caf36f4258714 (diff) | |
download | dexon-solidity-b7a86a124d658f0723f576e0f447773f3bec148b.tar dexon-solidity-b7a86a124d658f0723f576e0f447773f3bec148b.tar.gz dexon-solidity-b7a86a124d658f0723f576e0f447773f3bec148b.tar.bz2 dexon-solidity-b7a86a124d658f0723f576e0f447773f3bec148b.tar.lz dexon-solidity-b7a86a124d658f0723f576e0f447773f3bec148b.tar.xz dexon-solidity-b7a86a124d658f0723f576e0f447773f3bec148b.tar.zst dexon-solidity-b7a86a124d658f0723f576e0f447773f3bec148b.zip |
Refactor TypeChecker::visit(FunctionDefinition const&).
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 32cafb55..5f2443a2 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -299,32 +299,40 @@ bool TypeChecker::visit(FunctionDefinition const& _function) if (!_function.isConstructor() && !_function.isFallback() && !_function.isPartOfExternalInterface()) m_errorReporter.typeError(_function.location(), "Internal functions cannot be payable."); } - for (ASTPointer<VariableDeclaration> const& var: _function.parameters() + _function.returnParameters()) - { - if (type(*var)->category() == Type::Category::Mapping) + auto checkArgumentAndReturnParameter = [&](VariableDeclaration const& var) { + if (type(var)->category() == Type::Category::Mapping) { - if (!type(*var)->dataStoredIn(DataLocation::Storage)) - m_errorReporter.typeError(var->location(), "Mapping types can only have a data location of \"storage\"." ); + if (!type(var)->dataStoredIn(DataLocation::Storage)) + m_errorReporter.typeError(var.location(), "Mapping types can only have a data location of \"storage\"." ); else if (!isLibraryFunction && _function.isPublic()) - m_errorReporter.typeError(var->location(), "Mapping types for parameters or return variables can only be used in internal or library functions."); + m_errorReporter.typeError(var.location(), "Mapping types for parameters or return variables can only be used in internal or library functions."); } else { - if (!type(*var)->canLiveOutsideStorage() && _function.isPublic()) - m_errorReporter.typeError(var->location(), "Type is required to live outside storage."); - if (_function.isPublic() && !(type(*var)->interfaceType(isLibraryFunction))) - m_errorReporter.fatalTypeError(var->location(), "Internal or recursive type is not allowed for public or external functions."); + if (!type(var)->canLiveOutsideStorage() && _function.isPublic()) + m_errorReporter.typeError(var.location(), "Type is required to live outside storage."); + if (_function.isPublic() && !(type(var)->interfaceType(isLibraryFunction))) + m_errorReporter.fatalTypeError(var.location(), "Internal or recursive type is not allowed for public or external functions."); } if ( _function.isPublic() && !_function.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2) && - !typeSupportedByOldABIEncoder(*type(*var)) + !typeSupportedByOldABIEncoder(*type(var)) ) m_errorReporter.typeError( - var->location(), + var.location(), "This type is only supported in the new experimental ABI encoder. " "Use \"pragma experimental ABIEncoderV2;\" to enable the feature." ); + }; + for (ASTPointer<VariableDeclaration> const& var: _function.parameters()) + { + checkArgumentAndReturnParameter(*var); + var->accept(*this); + } + for (ASTPointer<VariableDeclaration> const& var: _function.returnParameters()) + { + checkArgumentAndReturnParameter(*var); var->accept(*this); } set<Declaration const*> modifiers; |