http://d.puremagic.com/issues/show_bug.cgi?id=5024

           Summary: Order of execution of invariant and pre/post
                    conditions
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: bearophile_h...@eml.cc


--- Comment #0 from bearophile_h...@eml.cc 2010-10-09 06:36:30 PDT ---
This is a D2 program that uses Contracts:


import std.c.stdio: printf;

class Foo {
    int x = 0;

    invariant() {
        printf("Foo invariant: %d\n", x);
        assert(x >= 0);
    }

    this() {
        printf("Foo constructor: %d\n", x);
        x = 0;
    }

    void setX(int newx)
        in {
            printf("Foo.setX precondition: %d\n", newx);
            assert(newx >= 0);
        } out {
            printf("Foo.setX postcondition: %d\n", x);
            assert(x == newx);
        } body {
            printf("Foo.setX body\n");
            x = newx;
        }
}

void main() {
    auto c = new Foo();
    c.setX(10);
}


This is the output of the program, DMD 2.049:

Foo constructor: 0
Foo invariant: 0
Foo.setX precondition: 10
Foo invariant: 0
Foo.setX body
Foo invariant: 10
Foo.setX postcondition: 10


But I think the Foo.setX precondition needs to run after the Foo invariant, and
the Foo.setX postcondition has to run before the Foo invariant.

See bug 5023

See also bug 3578 and bug 3856

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to