tsametype.nim 644 B

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