ttypeclasses.nim 919 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. type
  2. R = ref
  3. V = var
  4. D = distinct
  5. P = ptr
  6. T = type
  7. S = static
  8. OBJ = object
  9. TPL = tuple
  10. SEQ = seq
  11. var i: int
  12. var x: ref int
  13. var y: distinct int
  14. var z: ptr int
  15. const C = @[1, 2, 3]
  16. static:
  17. assert x is ref
  18. assert y is distinct
  19. assert z is ptr
  20. assert C is static
  21. assert C[1] is static[int]
  22. assert C[0] is static[SomeInteger]
  23. assert C isnot static[string]
  24. assert C is SEQ|OBJ
  25. assert C isnot OBJ|TPL
  26. assert int is int
  27. assert int is T
  28. assert int is SomeInteger
  29. assert seq[int] is type
  30. assert seq[int] is type[seq]
  31. assert seq[int] isnot type[seq[float]]
  32. assert i isnot type[int]
  33. assert type(i) is type[int]
  34. assert x isnot T
  35. assert y isnot S
  36. assert z isnot enum
  37. assert x isnot object
  38. assert y isnot tuple
  39. assert z isnot seq
  40. # XXX: These cases don't work properly at the moment:
  41. # assert type[int] isnot int
  42. # assert type(int) isnot int