2

I have a mapping like below.

struct A {
  //Some fields
}

mapping(address => A[]) testMapping;

When I add a new item to that array, I can use the code below and it works well.

testMapping[msg.sender].push()

In some code, I am also clearing this array like this.

delete testMapping[msg.sender]

After clearing, when I try to access length property of this array, it reverts the execution. This also happens when I try to access length property before adding any element to array.

The only thing that comes to my mind is when clearing the array setting length property to 0 like below.

testMapping[msg.sender].length = 0

But in after Solidity v0.6.0, length property became read-only, so this is not working as well.

Why this is happening, I could not find a solution online and in Solidity docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.