solidity/test/libsolidity/semanticTests/array/function_array_cross_calls.sol
Alex Beregszaszi 47167a42a7 Update tests
2021-05-27 18:31:54 +01:00

51 lines
1.3 KiB
Solidity

contract D {
function f(function() external returns (function() external returns (uint))[] memory x)
public returns (function() external returns (uint)[3] memory r) {
r[0] = x[0]();
r[1] = x[1]();
r[2] = x[2]();
}
}
contract C {
function test() public returns (uint256, uint256, uint256) {
function() external returns (function() external returns (uint))[] memory x =
new function() external returns (function() external returns (uint))[](10);
for (uint256 i = 0; i < x.length; i++) x[i] = this.h;
x[0] = this.htwo;
function() external returns (uint)[3] memory y = (new D()).f(x);
return (y[0](), y[1](), y[2]());
}
function e() public returns (uint256) {
return 5;
}
function f() public returns (uint256) {
return 6;
}
function g() public returns (uint256) {
return 7;
}
uint256 counter;
function h() public returns (function() external returns (uint)) {
return counter++ == 0 ? this.f : this.g;
}
function htwo() public returns (function() external returns (uint)) {
return this.e;
}
}
// ====
// compileViaYul: also
// ----
// test() -> 5, 6, 7
// gas irOptimized: 337455
// gas legacy: 463662
// gas legacyOptimized: 296513