Trying to work with a linked list I came across this strange behavior. Here the code
contract Test{
struct Node{
uint x;
uint linked; //index to next
bool nil;
}
Node [] public nodes;
function Test(){
nodes.push(Node(59,1,false));
nodes.push(Node(100,2,false));
nodes.push(Node(0,0,true));
}
function remove(uint nodeIdx){
Node node = nodes[nodeIdx];
Node linked = nodes[node.linked];
}
}
If I call remove(1) I should expect to see node equal to {100,2,false}, but in the debugger I got the following
Or in other words, node.x is valued with the length of the nodes array. I wonder why
Moreover,
- calling remove(anotherIndex) gives same results.
- declaring local var
Node storage node=nodes[nodeIdx]
gives same result