solang
solang copied to clipboard
Solang does not allow the deletion of memory array
This contract works on Solc, however fails on Solang:
contract Array{
function remove(uint256[] memory arr, uint256 e)
internal pure
{
unchecked {
uint idx = 0;
for(uint i = 0; i < arr.length; i++) {
if(arr[i] == e) {
idx = i;
}
}
for (uint i = idx; i < arr.length-1; i++){
arr[i] = arr[i+1];
}
delete arr[arr.length - 1];
}
}
}
The error is the following:
error: argument to 'delete' should be storage reference
┌─ /home/lucas/Documents/solang/examples/array.sol:16:13
│
16 │ delete arr[arr.length - 1];
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
Not sure what delete on memory arrays is supposed to do: on solc, there is no heap, so memory can't be freed.
A quick test suggests that the delete statement above is just a no-op in solc.
We should check the solc source for this.