[Issue 19032] New: Alias this does not interact with inheritance.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 27 23:44:50 UTC 2018


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

          Issue ID: 19032
           Summary: Alias this does not interact with inheritance.
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: wazar.leollone at yahoo.com

This case doesn't properly work.

interface IShort
{
    @property ref short getShort();
    alias getShort this;
}

interface IString
{
    @property ref string getString();
    alias getString this;
}

interface IDouble
{
    @property ref double getDouble();
    alias getDouble this;
}

class Test : IShort, IString, IDouble
{
    short a;
    string b;
    double d;

    this(short a, string b, double d)
    {
        this.a = a;
        this.b = b;
        this.d = d;
    }

    override @property ref short getShort()
    {
        return a;
    }

    override @property ref string getString()
    {
        return b;
    }

    override @property ref double getDouble()
    {
        return d;
    }
}


void test9()
{
    Test t = new Test(1, "2", 3.0);

    short a = t;
    string b = t;
    double d = t;

    assert(a == 1);
    assert(b == "2");
    assert(c == 3.0);
}

--


More information about the Digitalmars-d-bugs mailing list