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

Default values for fixed size arrays #109

Open
dddejan opened this issue Oct 18, 2019 · 1 comment
Open

Default values for fixed size arrays #109

dddejan opened this issue Oct 18, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@dddejan
Copy link
Member

dddejan commented Oct 18, 2019

contract Test {
    struct S {
        int x;
    }
    function test() {
        S[2][3] memory a;
        assert(a.length == 3);
        assert(a[0].length == 2);
        assert(a[1].length == 2);
        assert(a[0][0].x == 0);
        assert(a[1][0].x == 0);
        assert(a[2][0].x == 0);
        assert(a[0][1].x == 0);
        assert(a[1][1].x == 0);
        assert(a[2][1].x == 0);
    }
}

Currently we get:

solc-verify.py Test.sol
Test::test: ERROR
 - Test.sol:7:9: Assertion might not hold.
Test::[implicit_constructor]: OK
@dddejan dddejan added the enhancement New feature or request label Oct 18, 2019
@dddejan
Copy link
Member Author

dddejan commented Oct 18, 2019

Note also that for deep structures like above, proper recursive allocation also ensures non-aliasing.

ontract Test {
    struct S { int[2][3] x; }
    function test() public pure {
        S memory sm1;
        sm1.x[2][1] = 1;
        S memory sm2;
        sm2.x[2][1] = 2;
        assert(sm1.x[2][1] == 1); // Currently fails
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant