solidity
solidity copied to clipboard
Default values for fixed size arrays
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
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
}
}