Nested #if blocks inside macros produce unexpected AST ordering
27.5K reputation · 03 Apr 2025, 14:51 UTC
Goal: Determine how nested conditional compilation interacts with macro expansion
The Haxe compiler evaluates conditional compilation directives (#if, #elseif, #else) at compile‑time, but the interaction with macro‑based transformations is not fully specified. When complex nested #if blocks are expanded by a macro, the order in which the compiler evaluates those directives relative to the macro’s AST manipulation can vary, leading to different final abstract syntax trees for the same source and -D flags.
What is the evaluation order of nested #if directives when a macro expands them? Does the compiler guarantee deterministic AST output for a given set of -D flags? Are there any known workarounds to enforce a specific evaluation order?