Fix some type checks and tests for internal / external function parameters.

This commit is contained in:
chriseth 2016-10-13 17:51:46 +02:00
parent 97a3588701
commit 6f19559de0
3 changed files with 35 additions and 11 deletions

View File

@ -2075,12 +2075,12 @@ TypePointer FunctionType::encodingType() const
return TypePointer(); return TypePointer();
} }
TypePointer FunctionType::interfaceType(bool _inLibrary) const TypePointer FunctionType::interfaceType(bool /*_inLibrary*/) const
{ {
if (m_location != Location::External && m_location != Location::Internal) if (m_location != Location::External && m_location != Location::Internal)
return TypePointer(); return TypePointer();
if (_inLibrary) if (m_location != Location::External)
return shared_from_this(); return TypePointer();
else else
return make_shared<IntegerType>(8 * storageBytes()); return make_shared<IntegerType>(8 * storageBytes());
} }

View File

@ -7612,12 +7612,12 @@ BOOST_AUTO_TEST_CASE(calling_uninitialized_function)
contract C { contract C {
function intern() returns (uint) { function intern() returns (uint) {
function (uint) internal returns (uint) x; function (uint) internal returns (uint) x;
x(); x(2);
return 7; return 7;
} }
function extern() returns (uint) { function extern() returns (uint) {
function (uint) external returns (uint) x; function (uint) external returns (uint) x;
x(); x(2);
return 7; return 7;
} }
} }
@ -7676,7 +7676,7 @@ BOOST_AUTO_TEST_CASE(store_function)
function addTwo(uint x) returns (uint) { return x + 2; } function addTwo(uint x) returns (uint) { return x + 2; }
} }
contract C { contract C {
function (unction (uint) external returns (uint)) returns (uint) ev = eval; function (function (uint) external returns (uint)) returns (uint) ev = eval;
function (uint) external returns (uint) x; function (uint) external returns (uint) x;
function store(function(uint) external returns (uint) y) { function store(function(uint) external returns (uint) y) {
x = y; x = y;
@ -7695,7 +7695,7 @@ BOOST_AUTO_TEST_CASE(store_function)
BOOST_CHECK(callContractFunction("t()") == encodeArgs(u256(9))); BOOST_CHECK(callContractFunction("t()") == encodeArgs(u256(9)));
} }
// TODO: public function state variables, arrays // TODO: arrays, libraries
BOOST_AUTO_TEST_CASE(shift_constant_left) BOOST_AUTO_TEST_CASE(shift_constant_left)
{ {

View File

@ -4148,7 +4148,19 @@ BOOST_AUTO_TEST_CASE(function_type_parameter)
{ {
char const* text = R"( char const* text = R"(
contract C { contract C {
function f(function(uint) returns (uint) g) returns (function(uint) returns (uint)) { function f(function(uint) external returns (uint) g) returns (function(uint) external returns (uint)) {
return g;
}
}
)";
BOOST_CHECK(success(text));
}
BOOST_AUTO_TEST_CASE(function_type_returned)
{
char const* text = R"(
contract C {
function f() returns (function(uint) external returns (uint) g) {
return g; return g;
} }
} }
@ -4186,7 +4198,19 @@ BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter)
// as parameters to external functions. // as parameters to external functions.
char const* text = R"( char const* text = R"(
contract C { contract C {
function f(function(uint) returns (uint) x) { function f(function(uint) internal returns (uint) x) {
}
}
)";
BOOST_CHECK(expectError(text) == Error::Type::TypeError);
}
BOOST_AUTO_TEST_CASE(internal_function_returned_from_public_function)
{
// It should not be possible to return internal functions from external functions.
char const* text = R"(
contract C {
function f() returns (function(uint) internal returns (uint) x) {
} }
} }
)"; )";
@ -4197,7 +4221,7 @@ BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter_in_library_internal
{ {
char const* text = R"( char const* text = R"(
library L { library L {
function f(function(uint) returns (uint) x) internal { function f(function(uint) internal returns (uint) x) internal {
} }
} }
)"; )";
@ -4207,7 +4231,7 @@ BOOST_AUTO_TEST_CASE(internal_function_as_external_parameter_in_library_external
{ {
char const* text = R"( char const* text = R"(
library L { library L {
function f(function(uint) returns (uint) x) { function f(function(uint) internal returns (uint) x) {
} }
} }
)"; )";