tmacrotypes.nim 803 B

1234567891011121314151617181920212223242526
  1. discard """
  2. nimout: '''intProc; ntyProc; proc[int, int, float]; proc (a: int; b: float): int
  3. void; ntyVoid; void; void
  4. int; ntyInt; int; int
  5. proc (); ntyProc; proc[void]; proc ()
  6. voidProc; ntyProc; proc[void]; proc ()'''
  7. """
  8. import macros
  9. macro checkType(ex: typed; expected: string): untyped =
  10. echo ex.getTypeInst.repr, "; ", ex.typeKind, "; ", ex.getType.repr, "; ", ex.getTypeImpl.repr
  11. macro checkProcType(fn: typed): untyped =
  12. let fn_sym = if fn.kind == nnkProcDef: fn[0] else: fn
  13. echo fn_sym, "; ", fn_sym.typeKind, "; ", fn_sym.getType.repr, "; ", fn_sym.getTypeImpl.repr
  14. proc voidProc = echo "hello"
  15. proc intProc(a: int, b: float): int {.checkProcType.} = 10
  16. checkType(voidProc(), "void")
  17. checkType(intProc(10, 20.0), "int")
  18. checkType(voidProc, "procTy")
  19. checkProcType(voidProc)