Debian Codegraph @

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

raw
1 // REQUIRED_ARGS: -de
2 /*
3 TEST_OUTPUT:
4 ---
5 fail_compilation/fail19441.d(44): Error: cannot use `alias this` to partially initialize variable `wrap[0]` of type `Wrap10595`. Use `wrap[0].i`
6 ---
7 */
8
9 struct S10595
10 {
11 bool b = true;
12
13 bool test()
14 {
15 if (!b) // note: must be a check, not 'return b;'
16 return false;
17
18 return true;
19 }
20 }
21
22 struct Wrap10595
23 {
24 int i;
25 alias i this;
26 S10595 s;
27 }
28
29 void main()
30 {
31 {
32 Wrap10595[int] wrap;
33
34 wrap[0] = Wrap10595();
35 wrap[0].i = 0;
36
37 assert(wrap[0].s.test()); // ok
38 }
39
40 {
41 Wrap10595[int] wrap;
42
43 wrap[0] = Wrap10595();
44 wrap[0] = 0; // note: using 'alias this' to assign
45
46 assert(wrap[0].s.test()); // failure
47 }
48 }