[Issue 20233] opDispatch hides alias this properties

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 22 15:51:59 UTC 2019


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

--- Comment #6 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Max Samukha from comment #5)
> 'alias this' is irrelevant. The original test case fails because the array's
> .ptr property is called as a function. See the example in my previous
> comment (there was a typo: "apply" -> "to apply").

Yes, original test case fails for a different reason, but alias this isn't
usable if you have opDispatch, which is definitely a bug I would think. It
should trickle down to alias this if opDispatch doesn't handle it.

e.g.:

-----

struct S
{
   int length;
}

struct T
{
   S s;
   alias s this;
   int opDispatch(string fn, Args...)(Args args) if(fn != "length")
   {
      return 5;
   }
}

void main()
{
   T t;
   import std.stdio;
   writeln(t.length);
}

-------

Error: no property length for type T

If you comment out opDispatch it works.

--


More information about the Digitalmars-d-bugs mailing list