tcompiles.nim 482 B

12345678910111213141516171819202122232425262728293031
  1. # test the new 'compiles' feature:
  2. template supports(opr, x: untyped): bool =
  3. compiles(opr(x)) or compiles(opr(x, x))
  4. template ok(x) =
  5. static:
  6. assert(x)
  7. template no(x) =
  8. static:
  9. assert(not x)
  10. type
  11. TObj = object
  12. var
  13. myObj {.compileTime.}: TObj
  14. ok supports(`==`, myObj)
  15. ok supports(`==`, 45)
  16. no supports(`++`, 34)
  17. ok supports(`not`, true)
  18. ok supports(`+`, 34)
  19. no compiles(4+5.0 * "hallo")
  20. no compiles(undeclaredIdentifier)
  21. no compiles(undeclaredIdentifier)