teffects1.nim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. type
  10. TObj {.pure, inheritable.} = object
  11. TObjB = object of TObj
  12. a, b, c: string
  13. IO2Error = ref object of IOError
  14. proc forw: int {. .}
  15. proc lier(): int {.raises: [IO2Error].} =
  16. #[tt.Hint ^ 'lier' cannot raise 'IO2Error' [XCannotRaiseY] ]#
  17. writeLine stdout, "arg" #[tt.Error
  18. ^ can raise an unlisted exception: ref IOError
  19. ]#
  20. proc forw: int =
  21. raise newException(IOError, "arg")
  22. {.push raises: [Defect].}
  23. type
  24. MyProcType* = proc(x: int): string #{.raises: [ValueError, Defect].}
  25. proc foo(x: int): string {.raises: [ValueError].} =
  26. if x > 9:
  27. raise newException(ValueError, "Use single digit")
  28. $x
  29. var p: MyProcType = foo #[tt.Error
  30. ^
  31. type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
  32. ]#
  33. {.pop.}