Adding a new design constraint to D

Mike Parker aldacron at gmail.com
Mon Jun 20 09:48:49 UTC 2022


On Monday, 20 June 2022 at 09:27:59 UTC, FeepingCreature wrote:
> On Saturday, 18 June 2022 at 18:02:08 UTC, Max Samukha wrote:
>> On Saturday, 18 June 2022 at 08:04:55 UTC, FeepingCreature 
>> wrote:
>>
>>> a function in a module is "on the same level" as a method in 
>>> the class.
>>
>> If it is on the same level, then I would expect 'foo' below to 
>> lock the mutex and run the invariant check:
>>
>> ```d
>> synchronized class C
>> {
>>     private int x;
>>     private int y = 1;
>>
>>     invariant() { assert(y == x + 1); }
>> }
>>
>> void foo(C c, int x)
>> {
>>     c.x = x;
>>     c.y = x + 1;
>> }
>> ```
>
> And on reflection, I think I agree that it should.

Me, too. This is an aspect I hadn't considered before. It's given 
me an idea.



More information about the Digitalmars-d mailing list