[Issue 17449] New: [DIP1000] crash due to covariant conversion of scope delegate to delegate

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun May 28 05:52:57 PDT 2017


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

          Issue ID: 17449
           Summary: [DIP1000] crash due to covariant conversion of scope
                    delegate to delegate
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: r.sagitario at gmx.de

>From the dmd testsuite, runnable/xtest46.d:

module test;
struct Event9834
{
    void delegate() dg;
    void set(void delegate() h) pure { dg = h; }  // AV occurs
    void call() { dg(); }
}

void main()
{
    Event9834 ev;
    auto a = new class
    {
        Object o;
        this()
        {
            o = new Object;
            ev.set((){ o.toString(); });
        }
    };
    ev.call();
}

This runs fine when compiled with "dmd test", but crashes with an access
violation when compiled with "dmd test -dip1000".

This is caused by the delegate being inferred as "scope", and implicitely
converted to a non-scope delegate (thus not having a closure). This is ok when
the delegate is called by the callee (Event9834.set) directly, but not if it is
saved for later invocation.

--


More information about the Digitalmars-d-bugs mailing list