teffects1.nim 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. discard """
  2. cmd: "nim check $file"
  3. nimout: '''teffects1.nim(22, 28) template/generic instantiation from here
  4. teffects1.nim(23, 13) Error: can raise an unlisted exception: ref IOError
  5. teffects1.nim(22, 29) Hint: 'lier' cannot raise 'IO2Error' [XCannotRaiseY]
  6. teffects1.nim(38, 21) Error: type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
  7. .raise effects differ'''
  8. """
  9. {.push warningAsError[Effect]: on.}
  10. type
  11. TObj {.pure, inheritable.} = object
  12. TObjB = object of TObj
  13. a, b, c: string
  14. IO2Error = ref object of IOError
  15. proc forw: int {. .}
  16. proc lier(): int {.raises: [IO2Error].} =
  17. #[tt.Hint ^ 'lier' cannot raise 'IO2Error' [XCannotRaiseY] ]#
  18. writeLine stdout, "arg" #[tt.Error
  19. ^ can raise an unlisted exception: ref IOError
  20. ]#
  21. proc forw: int =
  22. raise newException(IOError, "arg")
  23. {.push raises: [Defect].}
  24. type
  25. MyProcType* = proc(x: int): string #{.raises: [ValueError, Defect].}
  26. proc foo(x: int): string {.raises: [ValueError].} =
  27. if x > 9:
  28. raise newException(ValueError, "Use single digit")
  29. $x
  30. var p: MyProcType = foo #[tt.Error
  31. ^
  32. type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
  33. ]#
  34. {.pop.}
  35. {.pop.}