solidity/test/libsolidity/semanticTests/array/function_memory_array.sol

43 lines
1.0 KiB
Solidity
Raw Normal View History

contract C {
function a(uint256 x) public returns (uint256) {
return x + 1;
}
function b(uint256 x) public returns (uint256) {
return x + 2;
}
function c(uint256 x) public returns (uint256) {
return x + 3;
}
function d(uint256 x) public returns (uint256) {
return x + 5;
}
function e(uint256 x) public returns (uint256) {
return x + 8;
}
function test(uint256 x, uint256 i) public returns (uint256) {
function(uint) internal returns (uint)[] memory arr =
new function(uint) internal returns (uint)[](10);
arr[0] = a;
arr[1] = b;
arr[2] = c;
arr[3] = d;
arr[4] = e;
return arr[i](x);
}
}
2020-05-05 15:22:54 +00:00
// ====
// compileViaYul: also
// compileToEwasm: also
// ----
// test(uint256,uint256): 10, 0 -> 11
// test(uint256,uint256): 10, 1 -> 12
// test(uint256,uint256): 10, 2 -> 13
// test(uint256,uint256): 10, 3 -> 15
// test(uint256,uint256): 10, 4 -> 18
// test(uint256,uint256): 10, 5 -> FAILURE