Debian Codegraph @

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

raw
1 /*
2 TEST_OUTPUT:
3 ---
4 fail_compilation/fail329.d(28): Error: variable `fail329.A.foo.__ensure.result` cannot modify result `result` in contract
5 ---
6 */
7
8 //import core.stdc.stdio;
9
10 /*******************************************/
11
12 class A
13 {
14 int x = 7;
15
16 int foo(int i)
17 in
18 {
19 //printf("A.foo.in %d\n", i);
20 assert(i == 2);
21 assert(x == 7);
22 //printf("A.foo.in pass\n");
23 }
24 out (result)
25 {
26 assert(result & 1);
27 assert(x == 7);
28 result++;
29 }
30 do
31 {
32 return i;
33 }
34 }
35
36 class B : A
37 {
38 override int foo(int i)
39 in
40 {
41 float f;
42 //printf("B.foo.in %d\n", i);
43 assert(i == 4);
44 assert(x == 7);
45 f = f + i;
46 }
47 out (result)
48 {
49 assert(result < 8);
50 assert(x == 7);
51 }
52 do
53 {
54 return i - 1;
55 }
56 }
57
58 void test1()
59 {
60 auto b = new B();
61 b.foo(2);
62 b.foo(4);
63 }