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

Simen Kjaeraas <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]

--- Comment #2 from Simen Kjaeraas <[email protected]> ---
There's a difference between &c.test as you use in the assert, and &C.test,
which is what you use in the static this(). The former requires an instance to
serve as the context for the delegate, while the latter does not.

That said, is this behavior useful? Should typeof(&C.test) really be void
function(int, int)? As demonstrated above, it's just plain wrong. The correct
type for typeof(&C.test) is probably void function(int, int, C), as
demonstrated below:

alias int function(int, int, C) Callback;

void passCallback ( Callback cb ) {
    auto c = new C;
    c.i = 30;
    assert(cb(10, 20, c) == 102030);
}

class C {
    int i;

    int test (int foo, int bar) {
        return foo*10000 + bar*100 + i;
    }
}

unittest {
    passCallback(cast(Callback)&C.test);
}

--

Reply via email to