November 02, 2023
https://issues.dlang.org/show_bug.cgi?id=24220

          Issue ID: 24220
           Summary: Static array of nested struct changes .init value at
                    runtime
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: snarwin+bugzilla@gmail.com

As of DMD 2.105.3, the following program asserts at runtime:

---
void main()
{
    int n;
    struct Nested
    {
        int fun() { return n; }
    }

    static a = Nested.init;
    auto b = Nested.init;
    assert(a is b); // ok

    static a1 = (Nested[1]).init;
    auto b1 = (Nested[1]).init;
    assert(a1[0] is b1[0]); // fails
}
---

The error message, with -checkaction=context, is:

---
core.exception.AssertError@bug.d(15): Nested(<context>: 0x0) !is
Nested(<context>: 0x7f8e09158000)
---

A variable initialized with Nested.init will always have a null context pointer, whether it is initialized at compile time or runtime. However, a variable initialized with (Nested[1]).init has a null context pointer when initialized at compile time, and a non-null context pointer when initialized at runtime.

For the sake of consistency, the context pointer should be null in all cases.

--