www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20233] New: opDispatch hides alias this properties

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

          Issue ID: 20233
           Summary: opDispatch hides alias this properties
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: micia inventati.org

In presence of `alias this`, `opDispatch` causes the compiler to ignore
any plain member of the aliased field which is not a property nor a callable
method. This reduces `alias this` usefulness and is possibly a bug.

This is possibly caused by the fact that `opDispatch` takes precedence
over `alias this`.

-----
module main;

struct Point
{
    int[2] coords;

    alias coords this;

    auto opDispatch(string name, A...)(args)
    {
        return mixin("this.coords." ~ name ~ "(args)");
    }
}

void main()
{
    import std.stdio;

    Point p;
    writeln(p.ptr, p.length);
}

-----

$ dmd alias-dispatch.d 
alias-dispatch.d(20): Error: no property ptr for type Point
alias-dispatch.d(20): Error: no property length for type Point

--
Sep 20 2019