First Draft: Static Single Assignment

Nick Treleaven nick at geany.org
Mon Nov 17 09:58:22 UTC 2025


On Monday, 17 November 2025 at 01:08:58 UTC, Walter Bright wrote:
> On 11/16/2025 2:08 PM, Nick Treleaven wrote:
>> ```d
>> final int f = 3;
>> f = 4; // error, f is final
>> int* p = &f; // error, cannot make mutable reference to final 
>> variable
>> const int* pc = &f; // ok
>> ```
>> 
>> So I assume `typeof(&f)` would be `const int*`?
>
> `final` is not part of the type system. So typeof(&f) would be 
> `int*`.

I think it needs to be `const(int)*` to protect `f` from ever 
being mutated. If `&f` is part of a complex expression (e.g. 
`(*[&f][0])++`) I think practically we can only enforce that 
using `const`.

>> ```d
>> int i;
>> final int* pi = &i;
>> auto p = pi;
>> ```
>> Is `p` final or const?
>
> ```d
> int* p = pi;
> ```

OK so `p` is mutable because it's a copy of `pi`. Makes sense, 
thanks.



More information about the dip.development mailing list