from solidity documentation
Assignments from storage to a local storage variable also only assign a reference.
In this contract, when I am intialising x in the function, it defaults to a data location in storage, so it must reference the data.
why deleting x is not deleting the data?
pragma solidity >=0.4.0 <0.7.0;
contract DeleteExample {
uint data;
uint[] dataArray;
function f() public {
uint x = data;
delete x; // sets x to 0, does not affect data
delete data; // sets data to 0, does not affect x
uint[] storage y = dataArray;
delete dataArray; // this sets dataArray.length to zero, but as uint[] is a complex object, also
// y is affected which is an alias to the storage object
// On the other hand: "delete y" is not valid, as assignments to local variables
// referencing storage objects can only be made from existing storage objects.
assert(y.length == 0);
}
}
but when we initialized y with storage, it clearly referenced to the original dataarray. I was under the impression that local variables will always be stored on in-memory until storage is defined explicitly. am I wrong?