0

I have this simple contract where I want to save struct B with the name "poop" and an empty array of type struct A in the list wow.

contract Test {
    struct A {
        uint balls;
    }
    
    struct B {
        string name;
        A[] As;
    }
    
    B[] public wow;
    
    function create(uint _n) public {
        B memory lol;
        lol.name = "poop";
        wow.push(lol);
    }
}

When compiling, I get UnimplementedFeatureError: Copying of type struct Test.A memory[] memory to storage not yet supported.

0

The problems is that B memory representation doesn't have the As member since it cannot have a storage arrays in memory.

Previous version ignored this and let you assign B, silently ignoring dynamic fields like storage arrays and mappings.

You can workaround by getting a reference to the pushed object and modifying that copy instead.

function create(uint _n) public {
    // get a reference to the pushed struct
    B storage lol = wow.push();

    // modify storage instance
    lol.name = "poop";
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.