tcps.nim 529 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. output: '''10
  3. string'''
  4. """
  5. # bug #18059
  6. type
  7. C = ref object of RootObj
  8. fn: ContProc
  9. ex: ref Exception
  10. ContProc = proc (c: C): C {.nimcall.}
  11. proc noop(c: C): C = c
  12. type
  13. Env[T] = ref object of C
  14. x: T
  15. proc foo_cont[U](c: C): C =
  16. proc afterCall[V](c: C): C =
  17. echo Env[V](c).x
  18. c.fn = afterCall[U]
  19. return noop(c)
  20. proc foo[T](x: T): C =
  21. return Env[T](fn: foo_cont[T], x: x)
  22. proc tramp(c: sink C) =
  23. while c != nil and c.fn != nil:
  24. c = c.fn(c)
  25. tramp foo(10)
  26. tramp foo("string")