class Human {
    static immutable MAX_AGE = 122;

    bool alive = true;
    int age = 0;
//Error: mutable method onlineapp.Human.checkAge is not callable using a const object
    invariant(checkAge());

    void growOlder()
    in(alive)
    out(; checkAge())
    {
        age++;
        if (age > MAX_AGE)
            die();
    }

    void die()
    in(alive)
    out(; !alive) {
        alive = false;
    }

    bool checkAge() {
        return age >= 0 && age <= MAX_AGE || !alive;
    }
}

void main() {
    Human h = new Human();
    h.growOlder();
}

What the hell does this even mean, and where does it come from? Adding `inout` to `checkAge` actually does cause it to compile and run too. WTF?

Reply via email to