teffects6.nim 746 B

12345678910111213141516171819202122232425262728293031323334353637
  1. discard """
  2. action: compile
  3. """
  4. # XXX: it is not actually tested if the effects are inferred
  5. type
  6. PMenu = ref object
  7. PMenuItem = ref object
  8. proc createMenuItem*(menu: PMenu, label: string,
  9. action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = discard
  10. var s: PMenu
  11. createMenuItem(s, "Go to definition...",
  12. proc (i: PMenuItem, p: pointer) {.cdecl.} =
  13. try:
  14. echo(i.repr)
  15. except ValueError:
  16. echo("blah")
  17. )
  18. proc noRaise(x: proc()) {.raises: [].} =
  19. # unknown call that might raise anything, but valid:
  20. x()
  21. proc doRaise() {.raises: [IoError].} =
  22. raise newException(IoError, "IO")
  23. proc use*() =
  24. noRaise(doRaise)
  25. # Here the compiler inferes that EIO can be raised.
  26. use()