Bug 20665 – std.concurrency.spawn should document not working with delegates
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2020-03-11T08:28:57Z
Last change time
2021-08-01T04:36:19Z
Assigned to
No Owner
Creator
Simen Kjaeraas
Comments
Comment #0 by simen.kjaras — 2020-03-11T08:28:57Z
std.concurrency.spawn only accepts function pointers and callable types without mutable aliasing as its first argument. A logical thing for a user to attempt is to use a delegate, like e.g. this:
struct S {
void fun() {}
void gun() {
import std.concurrency;
spawn(&fun); // Won't compile
}
}
This will not compile, with a somewhat confusing error message about "cannot deduce function from argument types". There should be an overload like this:
void spawn(F, T...)(F fn, T args)
if (isDelegate!F)
{
static assert(false, "Delegates can hold aliases to mutable state.");
}
In addition, the documentation should mention that this is a limitation, and why (delegate contexts have no constness, and so may alias mutable state).
Comment #1 by dlang-bot — 2020-05-29T19:06:26Z
@Biotronic created dlang/phobos pull request #7506 "Fix issue 20665 - std.concurrency.spawn should document not working with delegates" mentioning this issue:
- Fix issue 20665
https://github.com/dlang/phobos/pull/7506
Comment #2 by dlang-bot — 2021-08-01T04:36:19Z
dlang/phobos pull request #7506 "Fix issue 20665 - std.concurrency.spawn should document not working with delegates" was merged into master:
- abb2156487b7d7015cd8f059b1083297cfbee06b by Biotronic:
Fix issue 20665
- 69800d947552c198f6745564ada72d624b6ffe90 by RazvanN7:
Fix Issue 20665 - std.concurrency.spawn should document not working with delegates
https://github.com/dlang/phobos/pull/7506