Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solang loads vectors from storage incorrectly #933

Open
LucasSte opened this issue Jul 20, 2022 · 1 comment
Open

Solang loads vectors from storage incorrectly #933

LucasSte opened this issue Jul 20, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@LucasSte
Copy link
Contributor

      contract Testing {

    struct PaddedStruct {
        uint128 a;
        uint8 b;
        bytes32 c;
    }

    PaddedStruct[2][3][] stor_arr;

    function addData() public {
        PaddedStruct memory a = PaddedStruct(56, 1, "oi");
        PaddedStruct memory b = PaddedStruct(78, 6, "bc");
        PaddedStruct memory c = PaddedStruct(89, 4, "sn");
        PaddedStruct memory d = PaddedStruct(42, 56, "cn");
        PaddedStruct memory e = PaddedStruct(23, 78, "fr");
        PaddedStruct memory f = PaddedStruct(445, 46, "br");

        PaddedStruct[2][3] memory vec = [[a, b], [c, d], [e, f]];
        stor_arr.push(vec);
    }

    function getThis() public view returns (uint32) {
        PaddedStruct[2][3][] memory arr2 = stor_arr;

        return arr2.length;
    }
}
  

Calling getThis after addData returns 6, instead it should return 1. If we modify stor_arr to PaddedStruct[2][2][] stor_arr and do all the necessary changes, addData returns 4. I think we are incorrectly merging the first two dimensions into one.

@LucasSte LucasSte added the bug Something isn't working label Jul 20, 2022
@LucasSte
Copy link
Contributor Author

uint16[4][2][] simple_arr;
    function multiDim() public returns (uint32) {
        uint16[4][2] memory vec = [[uint16(1), 2, 3, 4], [uint16(5), 6, 7, 8]];
        simple_arr.push(vec);
        
        uint16[4][2][] memory mem_vec = simple_arr;
        return mem_vec.length;
    }

This returns 8 🤨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant