It gets complicated. It's essentially declarative, but order can still matter when a
static if introduces a new symbol. Aside from that, I don't believe that it ever matters, but as your example shows, when you introduce a new symbol in a
static if, and another
static if uses it, the order definitely can matter.
There has been some discussion recently about how to make it as consistent and intuitive as possible. So, particularly in corner cases, the situation may change in the near future. But I would expect that your example would continue to trigger the
static assert. The question is whether it will start to trigger the
static assert if you reverse the order of the
static if blocks, and I'm not sure that that's really been decided yet. The discussion on it in the compiler's newsgroup isn't entirely conclusive and a bit hard to follow IMHO, so I can't say for sure. But I expect that ordering will still matter in at least some cases which involve a
static if block introducing a new symbol.
This was recently posted by one of dmd's primary contributors:
At present, the order of compile-time evaluation is not defined; DMD
currently does it vaguely in lexical order but that is planned to
change in the near future. 'static if' and 'mixin' will be evaluated
in lexical order, before anything else is done. Afterwards,
everything else will be evaluated on-demand.
Apart from the "static if/mixin" pass, compilation can proceed in
parallel (though the current implementation doesn't yet do this) which
means there's no ordering (multiple items may complete compilation
So, hopefully that clarifies things.