Issue 19345 - std.concurrency does not work with structs of const value type
Summary: std.concurrency does not work with structs of const value type
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2018-10-31 02:40 UTC by Mathias LANG
Modified: 2024-12-01 16:34 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias LANG 2018-10-31 02:40:09 UTC
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.
Comment 1 Steven Schveighoffer 2019-01-10 19:11:37 UTC
Same thing with immutable.
Comment 2 berni44 2019-12-14 09:56:21 UTC
Maybe a duplicate of issue 13930. 

https://issues.dlang.org/show_bug.cgi?id=13930
Comment 3 Dlang Bot 2020-10-10 00:33:46 UTC
@tom-tan updated dlang/phobos pull request #7655 "Fix `receiveOnly` for non-assignable types (issue 13930, issue 19345)" fixing this issue:

- Fix issue 13930, 19345 - Fix receiveOnly for non-assignable types

https://github.com/dlang/phobos/pull/7655
Comment 4 Dlang Bot 2020-10-10 02:09:25 UTC
dlang/phobos pull request #7655 "Fix issue 13930, 19345 - Fix `receiveOnly` for non-assignable types " was merged into master:

- d86c1f605995b423dd1a467b2c1c530dc52adb1e by Tomoya Tanjo:
  Fix issue 13930, 19345 - Fix receiveOnly for non-assignable types

https://github.com/dlang/phobos/pull/7655
Comment 5 Dlang Bot 2020-10-10 23:23:27 UTC
dlang/phobos pull request #7657 "Revert "Fix issue 13930, 19345 - Fix `receiveOnly` for non-assignable types "" was merged into master:

- 756242350896019ffc7a7cbe05e838538a559f5a by Mathias LANG:
  Revert "Fix issue 13930, 19345 - Fix receiveOnly for non-assignable types"
  
  This reverts commit 4f4fef19400ff85eb4699d569b02b21299b254cc.

https://github.com/dlang/phobos/pull/7657
Comment 6 Dlang Bot 2020-10-13 09:34:25 UTC
@tom-tan created dlang/phobos pull request #7661 "Fix issue 13930, 19345 - Fix `receiveOnly` for non-assignable types" fixing this issue:

- Fix issue 13930, 19345 - Fix receiveOnly for non-assignable types

https://github.com/dlang/phobos/pull/7661
Comment 7 dlangBugzillaToGithub 2024-12-01 16:34:24 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9765

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB