--- Comment #12 from Steven Schveighoffer <>  2009-07-09 
08:23:21 PDT ---
you mean a kludge like COM interfaces?

But I digress...

Kludge is not the right word here, because what is implemented would fully
satisfy what is desired.  It may be worth while looking into how contravariance
can work in the general case.  At least in this case, it seems much less
complex, and I'd say it's pretty well contained.  That is, if this were
implemented, I don't see how it would translate to the expectation that
contravariance works in the general case (which has it's own problems).  In
fact, I'd say the current behavior is less consistent, since you can do
implicit casting of parameters to match the function call, but the same call
cannot be made by passing a delegate to a function that expects the base.

For instance, imagine the following:

struct S(T)
  T[] data;
  applyAll(void delegate(T t) dg)
    foreach(t; data) dg(t);

class C {}
class D : C {}

class X
  void foo(C c) {writefln(c);}

  void foo2(S!D s)
    s.applyAll(&foo); // would just work.
    // current requirement (a kludge IMO)
    void wrapper(D d) { foo(d); }

I would petition to leave this open as an enhancement, maybe one of the newly
found compiler gurus who can now modify dmd to add things can try making this
work as a test.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to