Check.hx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import haxe.macro.Compiler;
  2. import haxe.macro.Context;
  3. import haxe.macro.Expr;
  4. import haxe.macro.Type;
  5. class Check {
  6. static public function run() {
  7. Context.onAfterTyping(function(types) {
  8. for(type in types) {
  9. switch type {
  10. case TClassDecl(_.get() => cls) if (cls.name == 'Arr'):
  11. for(field in cls.fields.get()) {
  12. if(field.name == 'map') {
  13. var expr = field.expr();
  14. switch expr.expr {
  15. /*
  16. {
  17. var val = f(this.get);
  18. null;
  19. }
  20. */
  21. case TFunction({expr: {expr: TBlock(exprs)}}):
  22. switch exprs[0].expr {
  23. // var val = f(this.get);
  24. case TVar(_, {expr: TCall({expr: TLocal(_), t: t}, _)}):
  25. // type of `f` from expr above
  26. switch t {
  27. //Should be `Arr.T->map.S`. Before the fix it was `map.S->map.S`
  28. case TFun([{t: TInst(_.toString() => 'Arr.T',[])}], _):
  29. //success;
  30. return;
  31. case _:
  32. Context.error('Invalid type of "f(get())" in Arr.map: $t', exprs[0].pos);
  33. }
  34. case _:
  35. Context.error('Invalid expression of Arr.map block', exprs[0].pos);
  36. }
  37. case _:
  38. Context.error('Invalid expression of Arr.map', expr.pos);
  39. }
  40. }
  41. }
  42. case _:
  43. }
  44. }
  45. Context.error('Class "Arr" was not found', Context.currentPos());
  46. });
  47. }
  48. }