t6756.nim 300 B

12345678910111213141516171819202122232425
  1. discard """
  2. output: '''
  3. (v: 3)
  4. '''
  5. """
  6. import typetraits
  7. type
  8. A[T] = ref object
  9. v: T
  10. template templ(o: A, op: untyped): untyped =
  11. type T = typeof(o.v)
  12. var res: A[T]
  13. block:
  14. var it {.inject.}: T
  15. it = o.v
  16. res = A[T](v: op)
  17. res
  18. let a = A[int](v: 1)
  19. echo templ(a, it + 2)[]