Browse Source

changed checking for external type in VariableDeclaration::checkTypeRequirements()

changed error msg
cl-refactor
Liana Husikyan 10 years ago
parent
commit
4173a71846
  1. 17
      libsolidity/AST.cpp
  2. 14
      test/SolidityNameAndTypeResolution.cpp

17
libsolidity/AST.cpp

@ -338,7 +338,14 @@ void FunctionDefinition::checkTypeRequirements()
if (!var->getType()->canLiveOutsideStorage()) if (!var->getType()->canLiveOutsideStorage())
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage.")); BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
if (getVisibility() >= Visibility::Public && !(var->getType()->externalType())) if (getVisibility() >= Visibility::Public && !(var->getType()->externalType()))
BOOST_THROW_EXCEPTION(var->createTypeError("Internal type is not allowed for function with external visibility")); {
// todo delete when arrays as parameter type in internal functions will be implemented
ArrayType const* type = dynamic_cast<ArrayType const*>(var->getType().get());
if (getVisibility() == Visibility::Public && type)
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."));
}
} }
for (ASTPointer<ModifierInvocation> const& modifier: m_functionModifiers) for (ASTPointer<ModifierInvocation> const& modifier: m_functionModifiers)
modifier->checkTypeRequirements(isConstructor() ? modifier->checkTypeRequirements(isConstructor() ?
@ -379,6 +386,14 @@ void VariableDeclaration::checkTypeRequirements()
m_value->expectType(*m_type); m_value->expectType(*m_type);
if (m_isStateVariable && !m_type->externalType() && getVisibility() >= Visibility::Public) if (m_isStateVariable && !m_type->externalType() && getVisibility() >= Visibility::Public)
BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for state variables.")); BOOST_THROW_EXCEPTION(createTypeError("Internal type is not allowed for state variables."));
auto sharedToExternalTypes = FunctionType(*this).externalType(); // do not distroy the shared pointer.
auto externalFunctionTypes = dynamic_cast<FunctionType const*>(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 } else
{ {
// no type declared and no previous assignment, infer the type // no type declared and no previous assignment, infer the type

14
test/SolidityNameAndTypeResolution.cpp

@ -460,7 +460,7 @@ BOOST_AUTO_TEST_CASE(function_external_types)
uint a; uint a;
} }
contract Test { contract Test {
function boo(uint arg2, bool arg3, bytes8 arg4, bool[2] pairs, uint[] dynamic, C carg) external returns (uint ret) { function boo(uint arg2, bool arg3, bytes8 arg4, bool[2] pairs, uint[] dynamic, C carg, address[] addresses) external returns (uint ret) {
ret = 5; ret = 5;
} }
})"; })";
@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(function_external_types)
auto functions = contract->getDefinedFunctions(); auto functions = contract->getDefinedFunctions();
if (functions.empty()) if (functions.empty())
continue; continue;
BOOST_CHECK_EQUAL("boo(uint256,bool,bytes8,bool[2],uint256[],address)", functions[0]->externalSignature()); BOOST_CHECK_EQUAL("boo(uint256,bool,bytes8,bool[2],uint256[],address,address[])", functions[0]->externalSignature());
} }
} }
@ -503,6 +503,16 @@ BOOST_AUTO_TEST_CASE(function_external_call_not_allowed_conversion)
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
} }
// todo delete when implemented
BOOST_AUTO_TEST_CASE(arrays_in_internal_functions)
{
char const* text = R"(
contract Test {
function foo(address[] addresses) {}
})";
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
}
BOOST_AUTO_TEST_CASE(function_internal_allowed_conversion) BOOST_AUTO_TEST_CASE(function_internal_allowed_conversion)
{ {
char const* text = R"( char const* text = R"(

Loading…
Cancel
Save