www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22090] New: "alias this" conflicts with concatenating array

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 puremagic.com
          Reporter: dlang-bugzilla 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.

--
Jun 29 2021