tgeneric_closure.nim 485 B

1234567891011121314151617181920212223242526272829303132333435
  1. discard """
  2. output: '''
  3. 2
  4. 2
  5. 2
  6. '''
  7. """
  8. # bug 2659
  9. type
  10. GenProcType[T,U] = proc(x:T, y:var U)
  11. IntProcType = proc(x:int, y:var int)
  12. proc mult(x:int, y:var int) =
  13. y = 2 * x
  14. when true:
  15. var input = 1
  16. var output = 0
  17. var someIntProc:IntProcType = mult
  18. var someGenProc:GenProcType[int,int] = mult
  19. mult(input, output)
  20. echo output
  21. someIntProc(input, output)
  22. echo output
  23. # Uncommenting causes an error in the C compiler.
  24. someGenProc(input, output)
  25. echo output