www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19345] New: std.concurrency does not work with structs of


          Issue ID: 19345
           Summary: std.concurrency does not work with structs of const
                    value type
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

The following code:
 system unittest
    static struct Aggregate { const int a; const int[5] b; }
    static void t1(Tid mainTid)
        const sendMe = Aggregate(42, [1, 2, 3, 4, 5]);
        mainTid.send(0, sendMe);

    auto tid = spawn(&t1, thisTid);
    auto result = receiveOnly!Aggregate();
    immutable expected = Aggregate(42, [1, 2, 3, 4, 5]);
    assert(result == expected);

Will fail to compile and yield the following error message:
std/concurrency.d(777): Error: cannot modify struct instance
ret.__expand_field_0 of type Aggregate because it contains const or immutable

This is because `std.concurrency` creates a struct, then assign its fields

In some cases, it's possible to use `receive` as a workaround, which offers a
delegate interface.

Oct 30 2018