Assignment to fixed-size arrays is currently stricter than initialization.
This works:
byte[32] selected = prev_state.a;
but this fails:
with:
array assignment only supports array identifiers
This becomes blocking when combined with two other current restrictions:
return must be the last statement
- you cannot return separately from
if/else
That means a branch-dependent fixed-size array value can become impossible to express.
Exact example
contract C(byte[32] initA, byte[32] initB) {
byte[32] a = initA;
byte[32] b = initB;
function choose(State prev_state) : (State) {
byte[32] selected = prev_state.a;
if (selected[0] == 1) {
selected = prev_state.b;
}
return({
a: selected,
b: prev_state.b
});
}
entrypoint function main() {
(State next) = choose({a: a, b: b});
require(next.b == b);
}
}
This currently fails on:
There is no real workaround here:
- the chosen
byte[32] value depends on the branch
- the final
return must happen after the branch
- separate returns inside the branches are not allowed
- and unlike
byte, there is no scalar workaround for byte[32]
Expected behavior
At minimum, fixed-size array assignment should accept RHS expressions that are type-compatible with the target type, for example:
byte[32] = other_byte32
byte[32] = prev_state.hash
- more generally
T[N] = expr when expr matches T[N]
The compiler already knows the exact target size, and it already accepts expression initializers for fixed-size arrays at definition time. This looks like an implementation restriction in assignment rather than a necessary language rule.
Assignment to fixed-size arrays is currently stricter than initialization.
This works:
but this fails:
with:
This becomes blocking when combined with two other current restrictions:
returnmust be the last statementif/elseThat means a branch-dependent fixed-size array value can become impossible to express.
Exact example
This currently fails on:
There is no real workaround here:
byte[32]value depends on the branchreturnmust happen after the branchbyte, there is no scalar workaround forbyte[32]Expected behavior
At minimum, fixed-size array assignment should accept RHS expressions that are type-compatible with the target type, for example:
byte[32] = other_byte32byte[32] = prev_state.hashT[N] = exprwhenexprmatchesT[N]The compiler already knows the exact target size, and it already accepts expression initializers for fixed-size arrays at definition time. This looks like an implementation restriction in assignment rather than a necessary language rule.