On 01/25/2015 02:06 PM, Bayan Rafeh wrote:

is invariant() called during the destruction phase?

Something is fishy.

import std.stdio;

void main(){
    writeln("entered main");
    auto a = new A();
    writeln("leaving main");
}

class A {
    File file;

    this() {
        writeln("this");
    }

    ~this() {
        writeln("~this");
    }

    invariant() {
        writeln("invariant");
    }
}

The program produces the following output:

entered main
this
invariant
leaving main
invariant
invariant    <-- ?
~this
invariant    <-- ?

Removing the File member changes the output. Now two of the invariant calls are missing:

entered main
this
invariant
leaving main
invariant
~this

However, the last invariant is still there and I think by design: The destructor should see a valid state.

Ali

Reply via email to