www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20665] New: std.concurrency.spawn should document not working


          Issue ID: 20665
           Summary: std.concurrency.spawn should document not working with
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com

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).

Mar 11 2020