[Issue 22090] New: "alias this" conflicts with concatenating array with element

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 29 07:46:42 UTC 2021


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

          Issue ID: 22090
           Summary: "alias this" conflicts with concatenating array with
                    element
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dlang-bugzilla at thecybershadow.net

////////// test.d //////////
struct S
{
    S[] sub;
    alias sub this;
}

void main()
{
    S s;
    S[] arr;
    arr = arr ~ s;
    assert(arr.length == 1);
}
////////////////////////////


The assertion fails. Instead of doing the expected thing and concatenating s to
arr, the compiler chooses to concatenate arr with s.sub.

Note that

    arr ~= s;

works as expected.

--


More information about the Digitalmars-d-bugs mailing list