On Saturday, 27 January 2024 at 02:12:25 UTC, FairEnough wrote:

..
Any answer to this question has to take into account the other code in the module.

Of course, I can answer this question.

The code below demonstrates how D made it possible for me to make a mistake when I first used D (i.e. I had the unittest in the same module as the class).

Of course now I know, silly me, just put the unittest in its own file god-damitt!

But here is how that mistake could have been avoided without having to put that unittest in its very own module:

module someClass;

class C
{
    void increment() {++x;}
    private(this) int x;
}

unittest
{
    auto c = new C;
c.x++; // it seems to me, that this is not what that 'type' expects. c.increment(); // Thanks private(this) for helping me not make that mistake.
}

Reply via email to