www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 85] New: Array of classes doesn't function as array of interfaces

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: deewiant 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);
}
------------------


-- 
Apr 04 2006
parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail puremagic.com schrieb am 2006-04-04:
 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);
 }
 ------------------

Added to DStress as http://dstress.kuehne.cn/run/i/interface_24_A.d http://dstress.kuehne.cn/run/i/interface_24_B.d http://dstress.kuehne.cn/run/i/interface_24_C.d http://dstress.kuehne.cn/run/i/interface_24_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFENMm33w+/yD4P9tIRAlC3AJ9QVGQPHBKByi84so9CUlefOXz+LwCgw+Bw GPcAGQaUavOJYIyT6E6JiR8= =5NI1 -----END PGP SIGNATURE-----
Apr 06 2006