First Draft: Static Single Assignment

Peter C peterc at gmail.com
Sat Nov 22 23:21:20 UTC 2025


On Sunday, 16 November 2025 at 01:50:32 UTC, Walter Bright wrote:
> Oops! 
> https://github.com/WalterBright/documents/blob/master/final.md

In C#, in order to guarantee thread safety and ensure safe object 
publication, a single assignment [which thankfully uses the 
'readonly' keyword instead of 'sealed'] requires that a member 
field (in a class or struct) can only be assigned a value once, 
either at the point of declaration or before the constructor 
finishes executing.

It doesn't matter how that value is computed or where the 
assignment line is located, as long as it's within the 
constructor's execution path.

Presumably, this same rule would apply in D?

i.e.

public class SomeClass
{
     public readonly string someValue;

     void initValue() { someValue = "some value"; } // Error 
(SAA): A 'final' field cannot be assigned to (except in a 
constructor or a variable initializer)

}



More information about the dip.development mailing list