Replace casting of external functions to address by a member named "address".

This commit is contained in:
Daniel Kirchner
2019-08-19 14:56:04 +02:00
committed by chriseth
parent d3ea86b052
commit 9f6fff2120
12 changed files with 72 additions and 51 deletions
-19
View File
@@ -11201,25 +11201,6 @@ BOOST_AUTO_TEST_CASE(function_array_cross_calls)
ABI_CHECK(callContractFunction("test()"), encodeArgs(u256(5), u256(6), u256(7)));
}
BOOST_AUTO_TEST_CASE(external_function_to_address)
{
char const* sourceCode = R"(
contract C {
function f() public returns (bool) {
return address(this.f) == address(this);
}
function g(function() external cb) public returns (address) {
return address(cb);
}
}
)";
compileAndRun(sourceCode, 0, "C");
ABI_CHECK(callContractFunction("f()"), encodeArgs(true));
ABI_CHECK(callContractFunction("g(function)", fromHex("00000000000000000000000000000000000004226121ff00000000000000000")), encodeArgs(u160(0x42)));
}
BOOST_AUTO_TEST_CASE(copy_internal_function_array_to_storage)
{
char const* sourceCode = R"(
@@ -0,0 +1,11 @@
contract C {
function f() public returns (bool) {
return this.f.address == address(this);
}
function g(function() external cb) public returns (address) {
return cb.address;
}
}
// ----
// f() -> true
// g(function): hex"00000000000000000000000000000000000004226121ff00000000000000000" -> 0x42
@@ -1,5 +1,5 @@
contract C {
function f() public view returns (address) {
return address(this.f);
return this.f.address;
}
}
@@ -1,7 +1,7 @@
contract C {
function f() public view returns (address payable) {
return address(this.f);
return this.f.address;
}
}
// ----
// TypeError: (85-100): Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable.
// TypeError: (85-99): Return argument type address is not implicitly convertible to expected type (type of first return variable) address payable.
@@ -0,0 +1,9 @@
contract C {
struct S { uint a; }
function f() public pure returns(address) {
S memory s = S(42);
return s.address;
}
}
// ----
// TypeError: (129-138): Member "address" not found or not visible after argument-dependent lookup in struct C.S memory.
@@ -0,0 +1,5 @@
contract C {
struct S { uint address; }
}
// ----
// ParserError: (33-40): Expected identifier but got 'address'