The given model does not obey one of the current rules following the common typical straight-forward approach for realizing simulate-able / compilable Modelica models:
a model shall not change its differential index throughout the
simulation
Realizing such models is not explicitly prevented by the actual version of Modelica language specification guide and there is nothing against realizing that.
Common simulation environments won't simulate apparently such a simple model, unless it is explicitly stated that multi-modes of DAEs are allowed.
Now going a bit into details, the differential index informally corresponds to the inherent degree of implicit / explicit dependencies among state variables. There are two ways a differential index can change throughout the simulation, a structural way or numerical way.
In the structural way, the model (similar to the given one) is stated in terms of several branches of equation systems. Each branch corresponds to a different differential index. In the given model, a branch corresponds to a linear equation while the other corresponds to a differential equation. A typical implementation of structural analysis would reveal that the model corresponds to an ODE system (which is not true for the first branch). My guess here is that the linear equation is submitted to the ODE solver. If we add a dummy differential equation outside the if condition such as der(z) = -1, the system will be simulated since the structural analysis is accidentally (semi-)correct.
If we are dealing with higher-index DAEs in different branches, we may get a numerically imprecise solution, since the index reduction is not seperately conducted for each possible branch. Applying the solver to a non-reduced DAE may cause a draft in the numerical solution since an implicit algebraic equation was not explicitly revealed in the resulting reduced equation that is passed to the solver.
In the numerical way there are cases where different values of model parameters lead to different differential indices (think about a parameter value that changes a sophisticated equation to a trivial one). Similarly, the differential index may change its value during simulation runtime. This type is difficult to capture using the common ways of treating higher-index differential equations.
The structural index:The common approach is to approximate the differential index using s.c. structural index: which is a graph-based representation of the equation system out of which the differential index can be approximated. An ODE system has a structural index 0 while a non-differential equation system has a structural index -1. Index reduction is conducted using a combination of Pantelides algorithm and dummy derivatives methods, cf. relevant literatures. Such graph-based methods don't capture the numerical aspects of a varying differential index that is not the same during a simulation or different values of parameters.
Multi-modes DAEs, resulting from both types, are subject to active research and there have been novel publications dealing with multimode DAEs, cf. Hilding Elmqvist' publications at Modelica conferences and journals among other related publications to multi-mode DAEs (As a note I am not identifying what is the best publication regarding this topic).
If there is a universal role to follow, then this would be that all branches of a model should have the same structural index (and ideally the same differential index during a simulation). In the former, the structural index can be easily approximated by the modeler for small models. For large models, it is beneficial if the simulation environment can dump information regarding the graph-based structure (i.e. computational graph) of a given model, its differential index, etc. In the later type, this is difficult for the modeler to capture. It is ideal if the simulation environment can dump such information regarding a numerically varying differential index.