www.digitalmars.com         C & C++   DMDScript  

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

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

          Issue ID: 20665
           Summary: std.concurrency.spawn should document not working with
                    delegates
           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