[Issue 3075] void delegate(const(void)[]) should be implicitly convertable to void delegate(void[])

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 9 08:23:22 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3075





--- Comment #12 from Steven Schveighoffer <schveiguy at yahoo.com>  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); }
    s.applyAll(&wrapper);
  }
}

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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list