[Bug 85] New: Array of classes doesn't function as array of interfaces

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 4 09:05:35 PDT 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=85

           Summary: Array of classes doesn't function as array of interfaces
           Product: D
           Version: 0.151
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: deewiant at gmail.com


Testcase below - originally posted as a comment in Bug 65.

Note that while this can be worked around simply by changing the Class[] to
I[], the code as it is below generates an incorrect program.

------------------
interface I {
        I[] foo();
        uint x();
}

class Class : I {
        I[] foo() {
                // changing this to I[] f = new Class[1] fixes the bug
                Class[] f = new Class[1];
                f[0] = new Class;
                return f;
        }

        uint x() {
                return 0;
        }
}

void main() {
        Class c = new Class();
        assert (c.x == 0);
        assert (c.foo[0].x == 0);
}
------------------


-- 




More information about the Digitalmars-d-bugs mailing list