https://issues.dlang.org/show_bug.cgi?id=15832

--- Comment #8 from [email protected] ---
(In reply to Atila Neves from comment #7)
> In the following code, the length is garbage, and uncommenting an assert
> makes the problem move!

I think a garbage reference to the stack explains this well. Any change to the
stack between the Mock construction and a call to dg affects what dg sees when
it dereferences the garbage pointer. Adding/removing almost anything, including
asserts, is going to change what's on the stack.

You can also make the first assert in main fail. Or you can make the second one
pass when trying hard enough:

----
/* ... as above ... */

void messWithTheStack() {int[][4] x = void; x[0][0] = 42;}

void main() {
    //auto m = Mock!(typeof(dg))(dg);
    auto m = mock(dg); // this should be equivalent but crashes
    assert(dg(3) == 0);
    m.returnValue(42);
    messWithTheStack();
    assert(dg(3) == 42);
}
----

--

Reply via email to