The example that you provides does not trigger the error message in the MEX.
Also matlab/deterministic-simulations/perfect_foresight_solver_core.m uses a specific codepath for purely backward models, that should not call that MEX.
The point is that this MEX file is not designed to handle purely backward models. That would require a different algorithm, and we already have routines that do that.
So if for some reason you have a .mod file that calls that MEX with a purely backward model, then we should understand why, and add a trap.
It seems that the idea is, if the simulated paths are complex, to take their real part, and then to check whether this real part is actually a solution, by recomputing the residuals. So the MEX is only called for recomputing the stacked residuals, which are returned as the first output argument (though the real purpose of this MEX is to compute the Jacobian of the stacked dynamic problem, returned as its second output argument).
We have a similar issue in perfect_foresight_solver_core, which will also call the MEX to compute the residuals. This in turn is triggered by homotopy of perfect_foresight_solver. How do we want to proceed? Gracefully erroring out?
I think that, in both cases, we should trap the purely forward/backward cases, and then use another code path for computing the residuals (essentially a loop over a call to the dynamic file).