[Issue 2557] inconsistent behavior when taking reference to member without instance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 5 00:30:19 UTC 2017


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

Mike Franklin <slavo5150 at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |slavo5150 at yahoo.com

--- Comment #10 from Mike Franklin <slavo5150 at 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

--


More information about the Digitalmars-d-bugs mailing list