First Draft: Static Single Assignment
Peter C
peterc at gmail.com
Wed Dec 3 10:43:53 UTC 2025
On Wednesday, 3 December 2025 at 10:18:50 UTC, Nick Treleaven
wrote:
> On Wednesday, 3 December 2025 at 04:05:28 UTC, Peter C wrote:
>> class Bag
>> {
>> final int[] items; // This is a binding-level guarantee -
>> also acts an API invariant.
>> this() { items = []; }
>> }
>>
>> void main()
>> {
>> auto b = new Bag();
>> b.items ~= 1; // fine. still mutable.
>> b.items = []; // was expecting an error here??
>> }
>
> Just to note that final on a dynamic array `a` should mean that
> `a.ptr` and `a.length` never change, but elements e.g. `a[0]`
> can change. So if final was allowed on fields, both assignments
> above would error.
Yes, I forgot how dynamic arrays work.
Dynamic arrays are allocated on the heap and will incur 'a
reallocation' when their size changes (via ~= for example). So
appending, removing, subsequently reserving a size, or
subsequently reassigning explicately, should all be considered as
a being disallowed.
When you said "So if final was allowed on fields.." are you
saying final does not work yet on class fields? Is that why I get
no errors here?
More information about the dip.development
mailing list