solidity icon indicating copy to clipboard operation
solidity copied to clipboard

Default values for fixed size arrays

Open dddejan opened this issue 6 years ago • 1 comments
trafficstars

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 avatar Oct 18 '19 01:10 dddejan

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
    }
}

dddejan avatar Oct 18 '19 01:10 dddejan