1 /* 2 TEST_OUTPUT: 3 --- 4 fail_compilation/fail66.d(11): Error: constructor fail66.C1.this missing initializer for const field y 5 --- 6 */ 7 8 class C1 9 { 10 const int y; this()11 this() {} 12 } 13 14 /* 15 TEST_OUTPUT: 16 --- 17 fail_compilation/fail66.d(28): Error: cannot modify const expression c.y 18 --- 19 */ 20 class C2 21 { 22 const int y; this()23 this() { y = 7; } 24 } test2()25void test2() 26 { 27 C2 c = new C2(); 28 c.y = 3; 29 } 30 31 /* 32 TEST_OUTPUT: 33 --- 34 fail_compilation/fail66.d(43): Error: cannot modify const expression this.y 35 --- 36 */ 37 class C3 38 { 39 const int y; this()40 this() { y = 7; } foo()41 void foo() 42 { 43 y = 6; 44 } 45 } 46 47 /* 48 TEST_OUTPUT: 49 --- 50 fail_compilation/fail66.d(59): Error: cannot modify const expression x 51 --- 52 */ 53 class C4 54 { 55 static const int x; this()56 static this() { x = 5; } foo()57 void foo() 58 { 59 x = 4; 60 } 61 } 62 63 /* 64 TEST_OUTPUT: 65 --- 66 fail_compilation/fail66.d(73): Error: cannot modify const expression z5 67 --- 68 */ 69 const int z5; this()70static this() { z5 = 3; } test5()71void test5() 72 { 73 z5 = 4; 74 } 75 76 /* 77 TEST_OUTPUT: 78 --- 79 fail_compilation/fail66.d(89): Error: cannot modify const expression c.y 80 --- 81 */ 82 class C6 83 { 84 const int y; this()85 this() 86 { 87 C6 c = this; 88 y = 7; 89 c.y = 8; 90 } 91 } 92