tclosure_issues.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. discard """
  2. output: '''true
  3. (999, 0)
  4. ok 0
  5. ok 1
  6. ok 2
  7. '''
  8. """
  9. block tissue600:
  10. for i in 1..1:
  11. var reported = false
  12. proc report() =
  13. reported = true
  14. import sequtils
  15. block tissue1502def:
  16. let xs: seq[tuple[key: string, val: seq[string]]] = @[("foo", @["bar"])]
  17. let maps = xs.map(
  18. proc(x: auto): tuple[typ: string, maps: seq[string]] =
  19. (x.key, x.val.map(proc(x: string): string = x)))
  20. block tissue1642:
  21. var i = 0
  22. proc p() = inc(i)
  23. block tissue1846:
  24. type
  25. TBinOp[T] = proc (x,y: T): bool
  26. THeap[T] = object
  27. cmp: TBinOp[T]
  28. proc less[T](x,y: T): bool =
  29. x < y
  30. proc initHeap[T](cmp: TBinOp[T]): THeap[T] =
  31. result.cmp = cmp
  32. var h = initHeap[int](less[int])
  33. echo h.cmp(2,3)
  34. block tissue1911:
  35. proc foo(x: int) : auto =
  36. proc helper() : int = x
  37. proc bar() : int = helper()
  38. proc baz() : int = helper()
  39. return (bar, baz)
  40. # bug #11523
  41. proc foo(): proc =
  42. let a = 999
  43. return proc(): (int, int) =
  44. return (a, 0)
  45. echo foo()()
  46. block tissue7104:
  47. proc sp(cb: proc())=
  48. cb()
  49. sp:
  50. var i = 0
  51. echo "ok ", i
  52. sp():
  53. inc i
  54. echo "ok ", i
  55. sp do:
  56. inc i
  57. echo "ok ", i