[Issue 20494] Appending derived class array to an interface array.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jan 13 16:35:07 UTC 2020


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

moonlightsentinel at disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel at disroot.o
                   |                            |rg

--- Comment #1 from moonlightsentinel at disroot.org ---
Test case without phobos:

---------------------------

interface IFoo
{
    size_t foo(size_t i);
}

class Bar : IFoo
{
    size_t foo(size_t i)
    {
        return 2 * i;
    }
}

void main()
{
    IFoo[] f;
    Bar[] b = [ new Bar() ];

    // this works well and as expected
    f ~= b[0];
    assert(f[0].foo(0) == 0);

    // this append the array with invalid values
    f ~= b;
    assert(f[0].foo(5) == 10);
    assert(f[1].foo(11) == 22);
}

---------------------------

The last assert fails with 13 != 22 and never worked before.

--


More information about the Digitalmars-d-bugs mailing list