teffects1.nim 1.3 KB

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