tstrict_effects3.nim 705 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. discard """
  2. action: compile
  3. """
  4. {.push warningAsError[Effect]: on.}
  5. {.experimental: "strictEffects".}
  6. proc fn(a: int, p1, p2: proc()) {.effectsOf: p1.} =
  7. if a == 7:
  8. p1()
  9. if a<0:
  10. raise newException(ValueError, $a)
  11. proc main() {.raises: [ValueError].} =
  12. fn(1, proc()=discard, proc() = raise newException(IOError, "foo"))
  13. main()
  14. # bug #19159
  15. import macros
  16. func mkEnter() =
  17. template helper =
  18. discard
  19. when defined pass:
  20. helper()
  21. else:
  22. let ast = getAst(helper())
  23. # bug #6559
  24. type
  25. SafeFn = proc (): void {. raises: [] }
  26. proc ok() {. raises: [] .} = discard
  27. proc fail() {. raises: [] .}
  28. let f1 : SafeFn = ok
  29. let f2 : SafeFn = fail
  30. proc fail() = discard
  31. f1()
  32. f2()