tlambdadonotation.nim 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. discard """
  2. output: '''
  3. issue #11812
  4. issue #10899
  5. 123
  6. issue #11367
  7. event consumed!
  8. '''
  9. """
  10. echo "issue #11812"
  11. proc run(a: proc()) = a()
  12. proc main() =
  13. var test: int
  14. run(proc() = test = 0)
  15. run do:
  16. test = 0
  17. main()
  18. echo "issue #10899"
  19. proc foo(x: proc {.closure.}) =
  20. x()
  21. proc bar =
  22. var x = 123
  23. # foo proc = echo x #[ ok ]#
  24. foo: echo x #[ SIGSEGV: Illegal storage access. (Attempt to read from nil?) ]#
  25. bar()
  26. echo "issue #11367"
  27. type
  28. EventCB = proc()
  29. Emitter = object
  30. cb: EventCB
  31. Subscriber = object
  32. discard
  33. proc newEmitter(): Emitter =
  34. result
  35. proc on_event(self: var Emitter, cb: EventCB) =
  36. self.cb = cb
  37. proc emit(self: Emitter) =
  38. self.cb()
  39. proc newSubscriber(): Subscriber =
  40. result
  41. proc consume(self: Subscriber) =
  42. echo "event consumed!"
  43. proc main2() =
  44. var emitter = newEmitter()
  45. var subscriber = newSubscriber()
  46. proc foo() =
  47. subscriber.consume()
  48. emitter.on_event() do:
  49. subscriber.consume()
  50. # this works
  51. # emitter.on_event(foo)
  52. emitter.emit()
  53. main2()