Programming in D, page 155. shared static this() fails
H. S. Teoh
hsteoh at qfbox.info
Wed Jul 30 18:00:39 UTC 2025
On Wed, Jul 30, 2025 at 10:54:15AM -0600, Jonathan M Davis via Digitalmars-d-learn wrote:
[...]
> immutable int[] i;
>
> shared static this()
> {
> immutable(int)[] temp;
> temp ~= foo();
> temp ~= bar();
> i = temp;
> }
>
> But even the shared static constructor isn't allowed to mutate the
> value of i. It's allowed to initialize it exactly once.
[...]
In that case, there is a bug:
```
static immutable int[] data;
shared static this() {
data = [ 1 ];
data = [ 2 ]; // should not compile, but currently does
}
```
T
--
Why did the chicken cross the Möbius strip? To get to the same side!
More information about the Digitalmars-d-learn
mailing list