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

Mike Franklin <slavo5...@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slavo5...@yahoo.com

--- Comment #10 from Mike Franklin <slavo5...@yahoo.com> ---
For convenience, I'm adding the source code from the original post's attachment
here:

module method_ref;

class A {
    void fun() {}
}

void main() {
    /* This works correctly and can sometimes be very useful */
    A a = new A;
    void function() fn1 = &A.fun;
    void delegate() dg1;
    dg1.ptr = cast(void*)a;
    dg1.funcptr = fn1;
    dg1();
}

class B {
    /+ static /* works if static */ +/ void dofun() {
        /* Error: this for fun needs to be type A not type method_ref.B */
        A a = new A;
        void function() fn2 = &A.fun;
        void delegate() dg2;
        dg2.ptr = cast(void*)a;
        dg2.funcptr = fn2;
        dg2();
    }
}

It can be tested online here: https://run.dlang.io/is/9GAvd4

--

Reply via email to