When a contract calls itself using the .call method and attempts to pass a struct, it results in a revert with the following error output:
"error": "Failed to decode output: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.7.0)
An example of a contract that contains this error:
pragma solidity >=0.7.0 <0.9.0;
library Dict {
struct DictType {
int256 max_length;
int256 current_length;
}
}
contract Test {
function test() public returns (int256) {
Dict.DictType memory dict = Dict.DictType({max_length: 1, current_length: 1});
(bool test, bytes memory res) = address(this).call(abi.encodeWithSignature("temp(Dict.DictType)", dict));
require(test);
(int256 resDecoded) = abi.decode(res, (int256));
return resDecoded;
}
function temp(Dict.DictType memory dict) public pure returns (int256) {
return 19;
}
}
When the called method is in a library or other contract, or a base type like int256 is passed instead of a struct, no error occurs. I am aware that this is far from standard practice, but for my purposes I need to be able to use the .call method in a contract to call itself while passing a struct. Is there any way to accomplish this?