Defaulting delegate member variables to do-nothing stubs

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 18 11:08:03 PDT 2014


On Thu, 18 Sep 2014 10:47:39 -0700
"H. S. Teoh via Digitalmars-d" <digitalmars-d at puremagic.com> wrote:

> Is there a way to achieve this? If not, why not?
i believe that you can't put such delegate to .init due to
required context pointer. yet compiler must be able to detect that this
delegate is not using any context info and context pointer can be null
here.

> Would it be worth filing an enhancement request for this?
yes, i think that ER will be fine.

> Note that the lack of argumentless struct ctors exacerbates this
> problem, since there is no way to work around the lack of language
> support here.
the only way is to @disable this(), so nobody will create unitialized
struct. yet this reveals another bug(?):

  struct S {
    int v;
    @disable this ();
    this (int n=42) { v = n; }
  }

  void main () {
    auto s = S();
  }

z03.d(8): Error: constructor z03.S.this is not callable because it is
annotated with @disable

WHAT? we have a perfectly valid struct constructor with default arg
which can be called when S() constructed, yet compiler tells me that it
can't do that, 'cause i disabled completely different constructor?

this thing annoys me alot, and i believe that i will eventually fix it
regardless of it's status (bug/feature).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140918/537d7e81/attachment.sig>


More information about the Digitalmars-d mailing list