Type not found during @:build macro expansion
0 reputation · 26 Jun 2025, 10:50 UTC
Type Resolution in Build Macros
Haxe macros annotated with @:build operate during the compilation process before full type checking is completed. A specific challenge arises when these macros generate code that references types defined later within the same source file.
While the macro API allows for the generation of complex structures, the compiler's ability to resolve forward references in macro-generated code is inconsistent. This often results in a failure to link the generated identifiers to their subsequent declarations in the module.
Furthermore, the interaction between haxe.macro.Compiler.require and generic instantiations remains unclear when the type is only referenced via a macro-generated expression rather than a static declaration.
- Does the Haxe compiler guarantee a specific order of type resolution for code generated by
@:buildrelative to forward declarations in the same file? - How can a macro ensure that a generic instantiation is preserved in the final output when
Compiler.requireis used on a type that is only referenced within generated code?