https://issues.dlang.org/show_bug.cgi?id=24617

          Issue ID: 24617
           Summary: array runtime erroneously copies flags from existing
                    block
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: druntime
          Assignee: nob...@puremagic.com
          Reporter: schvei...@gmail.com

If an array slice starts from a GC allocated block that is *not* marked
appendable, the appendable flag never gets set until appending occurs.

example:

```d
struct S
{
    int[1] val;
}
void main()
{
    auto s = new S;
    int[] arr = s.val[];
    assert(arr.capacity == 0); // starts out without appendability
    arr.length = 2;
    assert(arr.capacity > 0); // this fails
    arr.reserve(100);
    assert(arr.capacity > 0); // this fails
    arr ~= 10;
    assert(arr.capacity > 0); // finally, this succeeds
}
```

The issue is that the `__arrayAlloc` function copies the original bits instead
of using the typeinfo to decide the new array bits if a BlkInfo has already
been looked up. I guess the thought is that using the TypeInfo to build the
bits is more expensive, and we "already have something".

Options are to just always use the typeinfo, or to check for the appendable bit
before using the old bits (but copying the other bits might be questionable as
well).

--

Reply via email to