Debian Codegraph @

gcc/testsuite/gdc.test/fail_compilation/fail100.d

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail100.d(24): Error: return value `f` of type `Class[]` does not match return type `I[]`, and cannot be implicitly converted
5 ---
6 */
7
8 // https://issues.dlang.org/show_bug.cgi?id=85
9 // Array of classes doesn't function as array of interfaces
10 interface I
11 {
12 I[] foo();
13 uint x();
14 }
15
16 class Class : I
17 {
18 I[] foo()
19 {
20 // changing this to I[] f = new Class[1] fixes the bug
21 Class[] f = new Class[1];
22 //I[] f = new Class[1];
23 f[0] = new Class;
24 return f;
25 }
26
27 uint x()
28 {
29 return 0;
30 }
31 }
32
33 void main()
34 {
35 Class c = new Class();
36 assert(c.x == 0);
37 assert(c.foo[0].x == 0);
38 }