solang icon indicating copy to clipboard operation
solang copied to clipboard

Solang does not allow the deletion of memory array

Open LucasSte opened this issue 3 years ago • 1 comments

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];
   │             ^^^^^^^^^^^^^^^^^^^^^^^^^^

LucasSte avatar May 06 '22 13:05 LucasSte

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.

seanyoung avatar Jun 21 '22 08:06 seanyoung