Recently, I made the mistake of trying to reference an enum pointer in a struct before it was set (see example below). I was wondering if it's possible for DMD to catch this mistake at compile time, as this currently compiles fine and segfaults on execution.

Thanks

----------------
enum State {
    ONE,
    TWO
}

struct TestA {
    private State *state;

    void method(ref State program_state) {
        this.state = &program_state;
    }

    this (int temp_arg) {
        import std.stdio;

        // Problem code
        if (*this.state == state.ONE)
            "ONE".writeln;
    }
}

void main() {
    State program_state = State.TWO;
    auto a = TestA(1);
    a.method(program_state);
}

Reply via email to