tisop.nim 752 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. discard """
  2. disabled: true
  3. """
  4. import typetraits
  5. type
  6. TRecord = (tuple) or (object)
  7. TFoo[T, U] = object
  8. x: int
  9. when T is string:
  10. y: float
  11. else:
  12. y: string
  13. when U is TRecord:
  14. z: float
  15. E = enum A, B, C
  16. macro m(t: typedesc): typedesc =
  17. if t is enum:
  18. result = string
  19. else:
  20. result = int
  21. var f: TFoo[int, int]
  22. static: assert(f.y.type.name == "string")
  23. when compiles(f.z):
  24. {.error: "Foo should not have a `z` field".}
  25. proc p(a, b: auto) =
  26. when a.type is int:
  27. static: assert false
  28. var f: TFoo[m(a.type), b.type]
  29. static:
  30. assert f.x.type.name == "int"
  31. echo f.y.type.name
  32. assert f.y.type.name == "float"
  33. echo f.z.type.name
  34. assert f.z.type.name == "float"
  35. p(A, f)