Trouble with receiveOnly and immutable(JSONValue)

Steven Schveighoffer schveiguy at
Thu Jan 10 18:20:55 UTC 2019

On 1/10/19 12:15 PM, rx wrote:
> alias SyncData = immutable(JSONValue);
> void worker(string filename) {
>    SyncData data = filename.readText.parseJSON;
>    send(ownerTid, data);
> }
> void main(string[] args) {
>    spawn(&worker, args[1]);
>    writeln(receiveOnly!SyncData);
> }
> I'm trying to send this immutable(JSONValue) back to the main thread but 
> when trying to compile, I get the following error:
>> /usr/include/dmd/phobos/std/concurrency.d(764): Error: cannot modify 
>> immutable expression ret.__expand_field_0
>> cc.d(15): Error: template instance 
>> `std.concurrency.receiveOnly!(immutable(JSONValue))` error instantiating
> Can anyone help out?

Looks like a long-standing bug (there are several related issues about 
sending/receiving immutable data). The way std.concurrency.receiveOnly 
works is it creates a temporary result, then puts the received item into 
the result, and then returns it. But you can't copy an immutable into a 
temporary that's already immutable.

e.g. it looks like this:

immutable int x;
x = 5; // error

I don't know if there's a specific "can't receive immutable data" issue 
report, but certainly, you can add your issue to the list.


More information about the Digitalmars-d-learn mailing list