Bug 19345 – std.concurrency does not work with structs of const value type

Status
REOPENED
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-10-31T02:40:09Z
Last change time
2024-12-01T16:34:24Z
Keywords
pull
Assigned to
No Owner
Creator
Mathias LANG
Moved to GitHub: phobos#9765 →

Comments

Comment #0 by pro.mathias.lang — 2018-10-31T02:40:09Z
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 by schveiguy — 2019-01-10T19:11:37Z
Same thing with immutable.
Comment #2 by bugzilla — 2019-12-14T09:56:21Z
Maybe a duplicate of issue 13930. https://issues.dlang.org/show_bug.cgi?id=13930
Comment #3 by dlang-bot — 2020-10-10T00:33:46Z
@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 by dlang-bot — 2020-10-10T02:09:25Z
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 by dlang-bot — 2020-10-10T23:23:27Z
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 by dlang-bot — 2020-10-13T09:34:25Z
@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 by robert.schadek — 2024-12-01T16:34:24Z
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