tsametype.nim 628 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. discard """
  2. output: '''true
  3. false
  4. true
  5. false
  6. true
  7. false
  8. true
  9. false
  10. true
  11. false'''
  12. """
  13. import macros
  14. macro same(a: typedesc, b: typedesc): untyped =
  15. newLit(a.getType[1].sameType b.getType[1])
  16. echo same(int, int)
  17. echo same(int, float)
  18. type
  19. SomeInt = int
  20. DistinctInt = distinct int
  21. SomeFloat = float
  22. DistinctFloat = distinct float
  23. echo same(int, SomeInt)
  24. echo same(int, DistinctInt)
  25. echo same(float, SomeFloat)
  26. echo same(float, DistinctFloat)
  27. type
  28. Obj = object of RootObj
  29. SubObj = object of Obj
  30. Other = object of RootObj
  31. echo same(Obj, Obj)
  32. echo same(int, Obj)
  33. echo same(SubObj, SubObj)
  34. echo same(Other, Obj)