summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/fail329.d
blob: 95aaaf445a9ffbd000b1d2c6cb16d52bb8a85ec8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
TEST_OUTPUT:
---
fail_compilation/fail329.d(28): Error: variable `fail329.A.foo.__ensure.result` cannot modify result `result` in contract
---
*/

//import core.stdc.stdio;

/*******************************************/

class A
{
    int x = 7;

    int foo(int i)
    in
    {
        //printf("A.foo.in %d\n", i);
        assert(i == 2);
        assert(x == 7);
        //printf("A.foo.in pass\n");
    }
    out (result)
    {
        assert(result & 1);
        assert(x == 7);
        result++;
    }
    do
    {
        return i;
    }
}

class B : A
{
    override int foo(int i)
    in
    {
        float f;
        //printf("B.foo.in %d\n", i);
        assert(i == 4);
        assert(x == 7);
        f = f + i;
    }
    out (result)
    {
        assert(result < 8);
        assert(x == 7);
    }
    do
    {
        return i - 1;
    }
}

void test1()
{
    auto b = new B();
    b.foo(2);
    b.foo(4);
}