[Issue 19345] New: std.concurrency does not work with structs of const value type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 31 02:40:09 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19345
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 at puremagic.com
Reporter: pro.mathias.lang at 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(sendMe);
mainTid.send(0, sendMe);
}
auto tid = spawn(&t1, thisTid);
tid.send(1);
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
members
```
This is because `std.concurrency` creates a struct, then assign its fields
here:
https://github.com/dlang/phobos/blob/9fcf1f1b77a3a10f5369466cce58e8af7dc8ebcf/std/concurrency.d#L773-L777
In some cases, it's possible to use `receive` as a workaround, which offers a
delegate interface.
--
More information about the Digitalmars-d-bugs
mailing list