tnestedprocs.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. discard """
  2. cmd: "nim check --hints:off $file"
  3. nimout: '''tnestedprocs.nim(27, 8) Error: 'inner' can have side effects
  4. > tnestedprocs.nim(29, 13) Hint: 'inner' calls `.sideEffect` 'outer2'
  5. >> tnestedprocs.nim(26, 6) Hint: 'outer2' called by 'inner'
  6. tnestedprocs.nim(45, 8) Error: 'inner' can have side effects
  7. > tnestedprocs.nim(47, 13) Hint: 'inner' calls `.sideEffect` 'outer6'
  8. >> tnestedprocs.nim(44, 6) Hint: 'outer6' called by 'inner'
  9. tnestedprocs.nim(58, 41) Error: type mismatch: got <proc ()> but expected 'proc (){.closure, noSideEffect.}'
  10. Pragma mismatch: got '{..}', but expected '{.noSideEffect.}'.
  11. '''
  12. errormsg: "type mismatch: got <proc ()> but expected 'proc (){.closure, noSideEffect.}'"
  13. """
  14. {.experimental: "strictEffects".}
  15. proc outer {.noSideEffect.} =
  16. proc inner(p: int) =
  17. if p == 0:
  18. outer()
  19. inner(4)
  20. outer()
  21. proc outer2 =
  22. proc inner(p: int) {.noSideEffect.} =
  23. if p == 0:
  24. outer2()
  25. inner(4)
  26. outer2()
  27. proc outer3(p: int) {.noSideEffect.} =
  28. proc inner(p: int) {.noSideEffect.} =
  29. if p == 0:
  30. p.outer3()
  31. inner(4)
  32. outer3(5)
  33. proc outer6 =
  34. proc inner(p: int) {.noSideEffect.} =
  35. if p == 0:
  36. outer6()
  37. inner(4)
  38. echo "bad"
  39. outer6()
  40. proc outer4 =
  41. proc inner(p: int) {.noSideEffect.} =
  42. if p == 0:
  43. let x: proc () {.noSideEffect.} = outer4
  44. x()
  45. inner(4)
  46. outer4()