teffects1.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. {.push raises: [Defect].}
  21. type
  22. MyProcType* = proc(x: int): string #{.raises: [ValueError, Defect].}
  23. proc foo(x: int): string {.nimcall, raises: [ValueError].} =
  24. if x > 9:
  25. raise newException(ValueError, "Use single digit")
  26. $x
  27. var p: MyProcType = foo #[tt.Error
  28. ^
  29. type mismatch: got <proc (x: int): string{.nimcall, noSideEffect, gcsafe.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
  30. Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'.
  31. .raise effects differ
  32. ]#
  33. {.pop.}
  34. {.pop.}