How can I push a value into an dynamic sized array within a function?
I have a function which builds an array dynamically to use this as a function argument afterwards:
function autoMintBatch(...) {
uint32[] xList;
uint32[] yList;
// ... y is declared properly ...
yList.push(y);
for (uint256 i = 0; i < idList.length; i++) {
xList.push(x++);
}
}
I get the following compilation error:
TypeError: Member "push" is not available in uint32[] memory outside of storage.
But when I change the variable declaration to storage like:
uint32[] storage xList;
another error appears:
TypeError: This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.
Is there any way to build an array dynamically within a function?