Macro.hx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import haxe.macro.Expr.Field;
  2. import haxe.macro.Context;
  3. class Macro {
  4. public static macro function buildMain(): Array<Field> {
  5. final pos = Context.currentPos();
  6. final bf = Context.getBuildFields();
  7. final type = Context.getType('Test2');
  8. switch (type) {
  9. case TInst(ctRef, _):
  10. final ct = ctRef.get();
  11. try {
  12. final ctor = ct.constructor.get().expr();
  13. } catch (e: Dynamic) {
  14. }
  15. Context.warning('This does not show if printStuff() calls error() or reportError()', pos);
  16. case _:
  17. }
  18. return bf;
  19. }
  20. public static macro function buildTest2(): Array<Field> {
  21. final pos = Context.currentPos();
  22. final bf = Context.getBuildFields();
  23. // Use error() or reportError() here -> Main Completion does not work, Eval crashes
  24. // Use warning() or info() -> Everything works as expected
  25. Context.reportError('Crashes HERE in eval.vm.callMacroApi', pos);
  26. return bf;
  27. }
  28. }