Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.concurrency does not work with structs of const value type #9765

Open
dlangBugzillaToGithub opened this issue Oct 31, 2018 · 6 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

pro.mathias.lang (@Geod24) reported this on 2018-10-31T02:40:09Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=19345

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

schveiguy (@schveiguy) commented on 2019-01-10T19:11:37Z

Same thing with immutable.

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2019-12-14T09:56:21Z

Maybe a duplicate of issue 13930. 

https://issues.dlang.org/show_bug.cgi?id=13930

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants