On Wednesday, 9 June 2021 at 17:56:24 UTC, Gregor Mückl wrote:
Consider the following code:

```d
class Foo {  }

class Bar { Foo foo = new Foo(); }

void main()
{
        Bar b1 = new Bar();
        Bar b2 = new Bar();

        assert(b1.foo != b2.foo);
}
```

The assert fails. This is completely surprising to me. Is this actually expected?

By design.
What you see is CTFE instance shared through class member initializer.

Use Bar ctor instead if you want them to be unique.

Yep, confusing for the first time.

Reply via email to