Ticket #1421 (new RFC)
[RFC] zero length FxA behaviour
Reported by: | plobsing | Owned by: | plobsing |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | none | Version: | 2.0.0 |
Severity: | medium | Keywords: | |
Cc: | Language: | ||
Patch status: | Platform: |
Description
FixedBooleanArray, FixedStringArray, FixedIntegerArray, and FixedFloatArray do not allow specifying a length of 0, giving a misleading error of "Fixed${type}Array: can't resize".
FixedPMCArray ignores being set to zero length, remaining uninitialized.
Allowing for zero lengthed arrays allows code that handles "0 or more elements" cases to avoid checking against the zero case. For example:
.sub 'fixed_ints_upto' .param int i .local pmc retv retv = new ['FixedIntegerArray'] retv = i $I0 = 0 loop: if $I0 >= i goto end_loop: retv[$I0] = $I0 inc $I0 goto loop end_loop: .return (retv) .end
This will currently fail. To avoid failures, we would have to check for a zero valued argument and handle that case separately.
Zero is a valid length for an array, so I propose that we allow FxAs to be set to zero length (and not be subsequently resizable).
Alternatively, the behaviour could be to ignore setting the length to zero (as is done now in FPA). However, this can be seen as violating the set once property of FxA length.