Merge pull request #2473 from ethereum/functiontype-sig

Add .selector member on function types
This commit is contained in:
Alex Beregszaszi
2017-09-13 17:35:48 +01:00
committed by GitHub
7 changed files with 132 additions and 1 deletions
+24
View File
@@ -10051,6 +10051,30 @@ BOOST_AUTO_TEST_CASE(delegatecall_return_value)
BOOST_CHECK(callContractFunction("get_delegated()") == encodeArgs(u256(1)));
}
BOOST_AUTO_TEST_CASE(function_types_sig)
{
char const* sourceCode = R"(
contract C {
function f() returns (bytes4) {
return this.f.selector;
}
function g() returns (bytes4) {
function () external returns (bytes4) fun = this.f;
return fun.selector;
}
function h() returns (bytes4) {
function () external returns (bytes4) fun = this.f;
var funvar = fun;
return funvar.selector;
}
}
)";
compileAndRun(sourceCode, 0, "C");
BOOST_CHECK(callContractFunction("f()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
BOOST_CHECK(callContractFunction("g()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
BOOST_CHECK(callContractFunction("h()") == encodeArgs(asString(FixedHash<4>(dev::keccak256("f()")).asBytes())));
}
BOOST_AUTO_TEST_SUITE_END()
}
@@ -6285,6 +6285,87 @@ BOOST_AUTO_TEST_CASE(modifiers_access_storage_pointer)
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(function_types_sig)
{
char const* text = R"(
contract C {
function f() returns (bytes4) {
return f.selector;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"selector\" not found");
text = R"(
contract C {
function g() internal {
}
function f() returns (bytes4) {
return g.selector;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"selector\" not found");
text = R"(
contract C {
function f() returns (bytes4) {
function () g;
return g.selector;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"selector\" not found");
text = R"(
contract C {
function f() returns (bytes4) {
return this.f.selector;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function f() external returns (bytes4) {
return this.f.selector;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function h() external {
}
function f() external returns (bytes4) {
var g = this.h;
return g.selector;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function h() external {
}
function f() external returns (bytes4) {
function () external g = this.h;
return g.selector;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
text = R"(
contract C {
function h() external {
}
function f() external returns (bytes4) {
function () external g = this.h;
var i = g;
return i.selector;
}
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
}
BOOST_AUTO_TEST_CASE(using_this_in_constructor)
{
char const* text = R"(