1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail10980.d(22): Error: variable fail10980.s1b of type struct immutable(S1) uses this(this), which is not allowed in static initialization
5 fail_compilation/fail10980.d(28): Error: variable fail10980.s1d of type struct immutable(S1) uses this(this), which is not allowed in static initialization
6 fail_compilation/fail10980.d(27): Error: static variable s1x cannot be read at compile time
7 fail_compilation/fail10980.d(28):        called from here: bar1()
8 fail_compilation/fail10980.d(38): Error: variable fail10980.s2b of type struct immutable(S2) uses this(this), which is not allowed in static initialization
9 fail_compilation/fail10980.d(44): Error: variable fail10980.s2d of type struct immutable(S2) uses this(this), which is not allowed in static initialization
10 fail_compilation/fail10980.d(43): Error: static variable s2x cannot be read at compile time
11 fail_compilation/fail10980.d(44):        called from here: bar2()
12 ---
13 */
14 
15 struct S1
16 {
thisS117     this(int) immutable {}
thisS118     this(this) {}
19 }
20 alias immutable(S1) IS1;
21 static immutable S1 s1a = IS1(1);   // OK
22 static immutable S1 s1b = s1a;      // NG
23 
foo1()24 S1 foo1() { S1 s1x; S1 s1y = s1x; return s1y; }
25 static immutable S1 s1c = foo1();   // OK
26 
bar1()27 ref S1 bar1() { static S1 s1x; return s1x; }
28 static immutable S1 s1d = bar1();   // NG
29 
30 
31 struct S2
32 {
33     int val;
thisS234     this(this) {}
35 }
36 alias immutable(S2) IS2;
37 static immutable S2 s2a = IS2(1);   // OK
38 static immutable S2 s2b = s2a;      // NG
39 
foo2()40 S2 foo2() { S2 s2x; S2 s2y = s2x; return s2y; }
41 static immutable S2 s2c = foo2();   // OK
42 
bar2()43 ref S2 bar2() { static S2 s2x; return s2x; }
44 static immutable S2 s2d = bar2();   // NG
45