I am trying to test out a function similar to the one shown below:
function add (Complex calldata x, Complex calldata y) pure returns (Complex memory result) {
result = Complex(x.a.add(y.a), x.b.add(y.b));
}
If the storage type of the parameters is memory
, I have no issues. However, if the storage type is calldata
, I cannot declare this type of parameters for the function, because I get this:
Type struct Complex memory is not implicitly convertible to expected type struct Complex calldata
The testing function is shown below:
function testAdd(int256 a1, int256 b1, int256 a2, int256 b2) external {
Complex memory x = Complex(SInteger.wrap(a1), SInteger.wrap(b1));
Complex memory y = Complex(SInteger.wrap(a2), SInteger.wrap(b2));
...
// The two statements below produce: Type struct Complex memory is not implicitly
// convertible to expected type struct Complex calldata
Complex calldata actual = x.add(y);
Complex calldata expected = Complex(SInteger.wrap(a1).add(SInteger.wrap(a2)), SInteger.wrap(b1).add(SInteger.wrap(b2)));
assertEq(SInteger.unwrap(actual.a), SInteger.unwrap(expected.a));
assertEq(SInteger.unwrap(actual.b), SInteger.unwrap(expected.b));
}
If I do instead declare x
and y
using memory
, then the following is shown:
Member “add” not found or not visible after argument-dependent lookup in struct Complex memory.