From 4352423fea12a3896af3580f2b3097674cdd1ae9 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 1 Apr 2015 15:19:33 +0200 Subject: [PATCH] miner changes in the implementation of the externalTypes function of FunctionType. better error messages for exeptions style fixes after review --- libsolidity/AST.cpp | 18 ++++++++---------- libsolidity/Types.cpp | 12 +++++++----- libsolidity/Types.h | 2 ++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index a111a6f88..d489a4489 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -339,12 +339,11 @@ void FunctionDefinition::checkTypeRequirements() BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage.")); if (getVisibility() >= Visibility::Public && !(var->getType()->externalType())) { - // todo delete when arrays as parameter type in internal functions will be implemented - ArrayType const* type = dynamic_cast(var->getType().get()); - if (getVisibility() == Visibility::Public && type) + // todo delete when will be implemented arrays as parameter type in internal functions + if (getVisibility() == Visibility::Public && var->getType()->getCategory() == Type::Category::Array) BOOST_THROW_EXCEPTION(var->createTypeError("Array type is not allowed as parameter for internal functions.")); else - BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for function with external visibility.")); + BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for public and external functions.")); } } for (ASTPointer const& modifier: m_functionModifiers) @@ -389,12 +388,11 @@ void VariableDeclaration::checkTypeRequirements() auto sharedToExternalTypes = FunctionType(*this).externalType(); // do not distroy the shared pointer. auto externalFunctionTypes = dynamic_cast(sharedToExternalTypes.get()); - TypePointers retParamTypes = externalFunctionTypes->getReturnParameterTypes(); - TypePointers parameterTypes = externalFunctionTypes->getParameterTypes(); - for (auto parameter: parameterTypes + retParamTypes) - if (!parameter && !(parameter->externalType())) - BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for state variables.")); - } else + for (auto parameter: externalFunctionTypes->getParameterTypes() + externalFunctionTypes->getReturnParameterTypes()) + if (!parameter || !(parameter->externalType())) + BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for public state variables.")); + } + else { // no type declared and no previous assignment, infer the type m_value->checkTypeRequirements(); diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index e784c6b8c..86b740262 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -1103,15 +1103,17 @@ TypePointer FunctionType::externalType() const TypePointers paramTypes; TypePointers retParamTypes; - for(auto type: m_parameterTypes) + for (auto type: m_parameterTypes) { - solAssert(!!type->externalType(), "To be included in external type of the function, the argument should have external type."); + if(!type->externalType()) + return TypePointer(); paramTypes.push_back(type->externalType()); } - for(auto param: m_returnParameterTypes) + for (auto type: m_returnParameterTypes) { - solAssert(!!param->externalType(), "To be included in external type of the function, the argument should have external type."); - retParamTypes.push_back(param->externalType()); + if(!type->externalType()) + return TypePointer(); + retParamTypes.push_back(type->externalType()); } return make_shared(paramTypes, retParamTypes, m_location, m_arbitraryParameters); } diff --git a/libsolidity/Types.h b/libsolidity/Types.h index 99fd878f0..cea711991 100644 --- a/libsolidity/Types.h +++ b/libsolidity/Types.h @@ -512,6 +512,8 @@ public: virtual Category getCategory() const override { return Category::Function; } + /// @returns TypePointer of a new FunctionType object. All input/return parameters are an appropriate external types of input/return parameters of current function. + /// Returns an empty shared pointer if one of input/return parameters does not have an externaltype. virtual TypePointer externalType() const override; explicit FunctionType(FunctionDefinition const& _function, bool _isInternal = true);